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:
29,540
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.
_________________
Martin Prikryl

Reply with quote

jirlbeck
Joined:
Posts:
9
Location:
Chicago

Re: session.ExecuteCommand syntax issue/problem

martin wrote:

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.

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
Joined:
Posts:
29,540
Location:
Prague, Czechia

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.
_________________
Martin Prikryl

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
Joined:
Posts:
29,540
Location:
Prague, Czechia

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?
_________________
Martin Prikryl

Reply with quote

jirlbeck
Joined:
Posts:
9
Location:
Chicago

Re: sesssion.commandExecute

martin wrote:

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?

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:
29,540
Location:
Prague, Czechia

Re: sesssion.commandExecute

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

Reply with quote

jirlbeck
Joined:
Posts:
9
Location:
Chicago

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

You can post new topics in this forum