Topic "session.ExecuteCommand syntax issue/problem"

Author Message
jirlbeck
[View user's profile]

Joined: 2014-03-25
Posts: 9
Location: Chicago
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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
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
jirlbeck
[View user's profile]

Joined: 2014-03-25
Posts: 9
Location: Chicago
prikryl 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
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
jirlbeck
[View user's profile]

Joined: 2014-03-25
Posts: 9
Location: Chicago
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
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
jirlbeck
[View user's profile]

Joined: 2014-03-25
Posts: 9
Location: Chicago
prikryl 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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24538
Location: Prague, Czechia
Ok, so call mySession.ExecuteCommand("/opt/spins/qa/hadoop_publishing/cleansing/bin/QArenameStoreFiles.sh")
_________________
Martin Prikryl
jirlbeck
[View user's profile]

Joined: 2014-03-25
Posts: 9
Location: Chicago
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.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License