Using the /command switch

Advertisement

JonWayn70
Donor
Joined:
Posts:
6
Location:
Bellingham, WA

Using the /command switch

I am trying to generate some code using the command switch. The code looks good to me based on the syntax I read from the website but it instantly fails when I run it. I am using vba to generate the code for what that's worth. The generated code looks like this:
"c:\program files (x86)\WinSCP\WinSCP.com" /ini=nul /command="option batch on" "option confirm off" ^
"open sftp://loginname:pwd@somesite.com/ -Hostkey=""ssh-rsa 2048 blah-blah=""" ^
 "lcd ""C:\Working\Access\Polk\""" ^
 "get ""ACI_DONE_33398.xml""" "close" "exit" /log="C:\Working\Access\Polk\CmdLog.xml"
First of all, the log file doesn't get created, and secondly, the file isn't downloaded either. Can someone tell me what I am missing? Thanks

Reply with quote

Advertisement

JonWayn70
Donor

Re: Using the /command switch

I actually have the buddy script that uses the /script instead of the /command switch. That one works. I was just going through the documentation of WinSCP and thought it would be neat to also not create a script file, which is what I understand that the /command switch does. So there is no script file. The posted script code is generated live using VBA.

Reply with quote

Guest

Re: Using the /command switch

I removed all of the line-continuation-characters, the carets from the code and it worked, so it must be that I entered them incorrectly. This is not a serious issue but I would like to know what I am doing wrong

Reply with quote

Guest

Re: Using the /command switch

The script file is attached. Even with just 1 linebreak it fails. I have tried carriage-return+line-feed (the standard newline characters in vba), carriage-return, and line-feed separately but neither is accepted

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Using the /command switch

I'm not sure I follow. What you have attached is a Windows batch file, which should be executed directly. It's not WinSCP script file.

As I wrote before, if you still have problems, we need an output of the batch file, at least.

Reply with quote

JonWayn70
Donor
Joined:
Posts:
6
Location:
Bellingham, WA

Re: Using the /command switch

I don't know what you are asking for. I have never created a winscp script file except for txt files like the one I posted. If there is such a thing as a winscp script, I am unaware of it. What extension does it have and wouldn't the contents of it be the same as in the file I posted, if say I needed the same task done? Please enlighten me. Secondly, I chose to use the /command switch so that a script file is not created or saved. In order to post that file, I merely intercepted the procedure and copied the code to the file just before execution. Ordinarily, with the /command switch, a file would not have been created/saved, at least to my awareness.

Reply with quote

martin
Site Admin
martin avatar

Re: Using the /command switch

Sorry, but you still didn't give us the information I've asked for. "We need an output of the batch file, at least".

Reply with quote

Guest

Re: Using the /command switch

Do you read my comments at all. I posted a file of the command as it would have been if a file were created. If that is not what you want, why don't you elaborate on what exactly it is that you want?

Reply with quote

Advertisement

jwomackgsa
Joined:
Posts:
2

Is there a particular reason you are trying to run all that in the /command versus using your code to write out a script file and then use /script. I think you might find that easier to do and debug as well.

Reply with quote

JonWayn70
Donor
Joined:
Posts:
6
Location:
Bellingham, WA

jwomackgsa wrote:

Is there a particular reason you are trying to run all that in the /command versus using your code to write out a script file and then use /script. I think you might find that easier to do and debug as well.
As a learner, I just wanted to put the /command switch to the test to increase my understanding of the software. I do indeed have the corresponding script which works. If the /command switch was made available then it must have been so it can be used. Are you suggesting that it should only be limited to a few commands? It would seem to me they went through the trouble of creating the caret functionality to enable long commands with multiple tasks. I am just trying to understand how to use the caret correctly so when it really matters I can get it to work. Thank you

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
36,052
Location:
Prague, Czechia

Re: Using the /command switch

Anonymous wrote:

Do you read my comments at all. I posted a file of the command as it would have been if a file were created. If that is not what you want, why don't you elaborate on what exactly it is that you want?
Yes, I'm reading your comments. You have posted your batch file. I'm asking you to post an output of the batch file (when executed).

Reply with quote

JonWayn70
Donor

Re: Using the /command switch

None is created. That is the whole purpose of using the /command rather than the /script switch, the latter of which works when used with the same code. Neither is a script nor the specified logfile created because going scriptless is one target, and the call ultimately fails, creating no logfile. However, the file I posted is exactly what the script would have contained, had one been created, so you have all you need unless I am missing something you're unclear on.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,052
Location:
Prague, Czechia

Re: Using the /command switch

Sorry, but that's hard to believe. When I execute your batch file (TestScript.txt renamed to TestScript.bat), even when all the paths are not valid in my environment, I get loads of output:
C:\JonWayn70>TestScript.bat                                                                                                                                                                                                         

C:\JonWayn70>"c:\program files (x86)\WinSCP\WinSCP.com" /log="C:\Working\CmdLog.xml" /ini=nul /command     "option batch on" "option confirm off" "open sftp://loginname:pwd2@somesite.com/ -Hostkey=""ssh-rsa 2048 blahyadablah=""" "lcd ""C:\Working\""" "get ""ACI_DONE_15524.xml""" "close" "exit" 
batch           on        
confirm         off       
Error occurred during logging. It's been turned off.
Can't open log file 'C:\Working\CmdLog.xml'.

System Error.  Code: 2.

The system cannot find the file specified
Searching for host...
Connecting to host...
Authenticating...
Host key does not match configured key fingerprint "ssh-rsa 2048 blahyadablah="!
Host key fingerprint is ssh-rsa 2048 9xOXCfxuuXsHJq47v6uotqYh7TH/Zs2USGKdpXMBdHM=.

Authentication failed.
Error changing directory to 'C:\Working\'.
System Error.  Code: 2.

The system cannot find the file specified
No session.
No session.
C:\JonWayn70>
Are you really claiming that you get something like this?
C:\JonWayn70>TestScript.bat                                                                                                                                                                                                         

C:\JonWayn70>"c:\program files (x86)\WinSCP\WinSCP.com" /log="C:\Working\CmdLog.xml" /ini=nul /command     "option batch on" "option confirm off" "open sftp://loginname:pwd2@somesite.com/ -Hostkey=""ssh-rsa 2048 blahyadablah=""" "lcd ""C:\Working\""" "get ""ACI_DONE_15524.xml""" "close" "exit" 

C:\JonWayn70>
Please post a screenshot.

output.png

Reply with quote

Advertisement

You can post new topics in this forum