Forum Discussion

Monika1's avatar
Monika1
New Contributor
7 years ago

Not able to get file name through groovy script from remote server

I used below code on my soap ui project in groovy script to search a file with content using SFTP.

But i am getting process.exitValue = 2 and IO Exepction Stream Closed.

I am running this code on windows.

Can anyone help what is error in this code 

 

 

 

 

import com.jcraft.jsch.*
//
// Properties
//
def testCase = testRunner.testCase;


def String ftpHost = testCase.getPropertyValue("ftpHost")
def int ftpPort = testCase.getPropertyValue("ftpPort").toInteger()
def String ftpUsername = testCase.getPropertyValue("ftpUsername")
def String ftpPassword = testCase.getPropertyValue("ftpPassword")
def String localFilePath = testCase.getPropertyValue("localFilePath")
def String remoteFileDir = testCase.getPropertyValue("remoteFileDir")
//
Session session = null
Channel channel = null
try {
log.info("Starting sftp upload process")
JSch ssh = new JSch()

session = ssh.getSession(ftpUsername, ftpHost, ftpPort)
session.setConfig("StrictHostKeyChecking", "no"); //auto accept secure host
session.setPassword(ftpPassword)
session.connect()
log.info("Connected to session")

channel = session.openChannel("sftp")
channel.connect()
log.info("Connected to channel")

ChannelSftp sftp = (ChannelSftp) channel;
sftp.cd(remoteFileDir);
command = "find . -type f -exec grep -il 'abcas' {} \\;"


def process = command.execute()
def outputStream = new StringBuffer()
def errorStream = new StringBuffer()
process.waitForProcessOutput(outputStream, System.err);
log.info outputStream .toString();
process.consumeProcessOutput(outputStream, errorStream)
process.waitFor()
log.info process.exitValue()
log.info("return code: ${process.exitValue()}")
log.error("standard error: ${process.err.text}")
log.info("standard out: ${process.in.text}" + outStream.toString())
context.testCase.setPropertyValue("propertyName", outStream.toString())

4 Replies

  • Monika1's avatar
    Monika1
    New Contributor

    Hi Rao,

     

    I dont want to put file on sftp server.

    I want to search a fileName having content abc in file and then i want to download that file in my local.

    Can you please help me on that.

    I used code mentioned in my post but that is now working.

     

    Thanks,

    • nmrao's avatar
      nmrao
      Champion Level 3
      Is find command working as desired? Did you try it?
  • Monika1's avatar
    Monika1
    New Contributor

    Yes i tried on putty.

    It is working fine.

     

    i added one more line in code for getting error : 

    log.info "Std Err: process.err.text"

     

    it is giving 

    Std Err: FIND: Parameter format not correct