session.ExecuteCommand syntax issue/problem

Advertisement

jirlbeck
Joined:
Posts:
9
Location:
Chicago

session.ExecuteCommand syntax issue/problem

The following line has a syntax error when running from WinSCP in Excel using VBA:
mySession.ExecuteCommand(executionPath & Command)
Where executionPath is the remote unix filepath: "/opt/spins/qa/hadoop_publishing/cleansing/bin" and the Command is "./!""QArenameStoreFiles.sh", which is a bash script. I am using the /! syntax to select the current remote path as the directory where the shell script exists. The command line continually times out with "Terminated by user." What am I doing wrong?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: session.ExecuteCommand syntax issue/problem

It looks like you think that you can execute custom commands with Session.ExecuteCommand. You cannot, you need to use exact command as if you type it on terminal. That's for SCP and SFTP protocol, with FTP it's completely different.

Reply with quote

jirlbeck

Re: session.ExecuteCommand syntax issue/problem

And what would it look like? I have been successful with command.putFiles and command.GetFiles. I am getting an error code 260, command not found and it appears that the remote filepath is acceptable. I added a ! to the beginning of the filepath and that worked for that piece but now I get a message, "QArenameStoreFiles.sh command not found." Can you offer a syntax example that may work? I'm using SCP. I'd be grateful - JI

Reply with quote

martin
Site Admin
martin avatar

Re: session.ExecuteCommand syntax issue/problem

Sorry, I'm getting lost. Please show command syntax that works on SSH terminal that you want to execute using WinSCP. And show you full code calling Session.ExecuteCommand.

Reply with quote

jirlbeck
Joined:
Posts:
9
Location:
Chicago

sesssion.commandExecute

I have this in 2 functions called from a "main" sub-routine. In the first I establish the WinSCP connection, storing the session information in a Global public variable. I also pass the filepath and the command as parameters:
executionPath = "!/opt/spins/qa/hadoop_publishing/cleansing/bin"
command = "QArenameStoreFiles.sh"
Public Sub InitiateSession(ByRef mySession As Session)
    
    Dim mySessionOptions As New sessionOptions
    
    With mySessionOptions
        .Protocol = Protocol_Sftp
        .PortNumber = 22
        .HostName = "10.104.252.100"
        .UserName = "qausr"
        .Password = "had00p"
        .SshHostKeyFingerprint = "ssh-rsa 2048 17:ce:ee:6c:14:39:eb:5e:9d:6d:89:5d:e4:4e:cc:58"
    End With
 
' Connect to WinSCP
    mySession.Open mySessionOptions
 
End Sub 'InitiateSession
In the second I attempt to execute the command using the existing session and sessionOptions:
Public Function Execute_renameStoreFiles(ByVal Command As String) As CommandExecutionResult
    
    Dim myTransferOptions As New TransferOptions
    Dim transferResult As TransferOperationResult
 
    exeCommand = (executionPath & " !&" & Command)
    
    Set transferResult = mySession.ExecuteCommand(exeCommand)
 
End Function    'Execute_renameStoreFiles

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: sesssion.commandExecute

Again, what the command you want to execute should looks like (as if you type it on terminal)?

Is it /opt/spins/qa/hadoop_publishing/cleansing/bin/QArenameStoreFiles.sh?

Reply with quote

jirlbeck

Re: sesssion.commandExecute

Yes, that's correct. I execute the command from the bin directory and precede it with a ./ to indicate using the current filepath. And so, from bin I type ./QArenameStoreFiles.sh.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: sesssion.commandExecute

Ok, so call
mySession.ExecuteCommand("/opt/spins/qa/hadoop_publishing/cleansing/bin/QArenameStoreFiles.sh")

Reply with quote

jirlbeck

session.CommandExecute

It's working. Inside the QArenameStoreFiles.sh I had a bash script with parameters. I did not have the full file path defined for the script within the script. I added the full path and walla! it is now running. Thanks VERY much for the help.

Reply with quote

Advertisement

AP
Guest

Timeout waiting for WinSCP to respond

I m trying to run a shell script which is just doing a ls in it. The script runs perfectly fine when ran directly from root dir as sh test.sh

But when I try using executeCommand I get the following error.

I have attached the output also. What I feel is the script is not starting.
PLease suggest.
winscp> call /home/root/test.sh
Searching for host...
Connecting to host...
Authenticating...
Using username "root".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Exception thrown: 'System.TimeoutException' in WinSCPnet.dll
The thread 0x43c0 has exited with code 0 (0x0).
Error: System.TimeoutException: Timeout waiting for WinSCP to respond
   at WinSCP.Session.CheckForTimeout(String additional)
   at WinSCP.PatientFileStream.Wait(Int32& interval)
   at WinSCP.PatientFileStream.Read(Byte[] array, Int32 offset, Int32 count)
   at System.Xml.XmlTextReaderImpl.ReadData()
   at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
   at System.Xml.XmlTextReaderImpl.ParseText()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at WinSCP.SessionLogReader.DoRead()
   at WinSCP.SessionLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.Session.ExecuteCommand(String command)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Timeout waiting for WinSCP to respond

AP wrote:

I m trying to run a shell script which is just doing a ls in it. The script runs perfectly fine when ran directly from root dir as sh test.sh
...
Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Also where does the output your have posted come from? How did you obtain it? It's a strange combination of WinSCP scripting output and .NET exception.

Reply with quote

Guest

Re: Timeout waiting for WinSCP to respond

Hi Martin,
I have attached the log.
Please check
  • runscript.log (11.7 KB, Private file)

Reply with quote

AP
Guest

Re: Timeout waiting for WinSCP to respond

Hi Martin,
I have attached another log as well. PLease check the previous and this log file for reference. I see 2 different flows which occur with the same code.
Please check
  • runscript_2.log (9.58 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Timeout waiting for WinSCP to respond

Your script requires a terminal:
tty: standard input: Inappropriate ioctl for device
You cannot run such scripts in WinSCP. WinSCP is not a remote terminal.

Reply with quote

Advertisement

You can post new topics in this forum