I am trying to write a WinSCP script. I tried the example at,
https://winscp.net/eng/docs/guide_automation#parametrized
but the parameter value is not taken by the script.
When the script is invoked as,
winscp.com /script=testscript /parameter param1
The following occurs:
First,
Searching for host
host not found
is displayed.
Followed by, actually connecting to the host using the
"open command"
but the parameter is never substituted.
It still displays as %1
I don't know which example you are talking about but I will show you some sample code that I have. I hope it helps. This code is all located in a .bat file.
In this example, a variable %folder% is made with the name of today's date in the format of 2/28/2012. I then ask the user for their username and it gets saved in the variable %username%, same with %password%. I then used the %folder% variable to make a directory with a folder named %folder%.
Now we dive into actual 'WinSCP Code'.
I then located the path towards my WinSCP.exe and then called console. After console was called, I connected to my WinSCP server using the 'open' command and the %Username% and %Password% variables.
@ECHO OFF
cls
set folder=%date:~4,2%-%date:~7,2%-%date:~10,4%
SET /P username="Enter Username: "
IF "%username%"=="" GOTO Error
SET /P password="Enter Password: "
rem -- Clear Screen to hide password
cls
IF "%password%"=="" GOTO Error
md C:\Logs\%folder%\int-rpt01\
"C:\""Program Files""\WinSCP\WinSCP.exe" /console /command "option batch abort"
"option confirm off" "open sftp://%username%:%password%@server.server.net:22"
"get /opt/ibm/cognos/c10_64/logs/cogserver.* C:\CogServerLogs\%folder%\int-rpt01\" "exit"
I hope this helps. Any more information on which example you are using and or how you are using it would be appreciated.
For reference, since I just landed here when attempting to work this out myself, the syntax should be:
In your script file:
put "%1%" %2%
and then call it from the command line with
winscp.com /script=script.file /parameter foo.txt bar/
This will resolve the script to
put "foo.txt" bar/
To pass your parameter to the open
command, follow it by %1%
, ideally wrapped to double-quotes:
open "%1%"
Refer to:
https://winscp.net/eng/docs/scripting#syntax
See also parametrized script example.
Also from the behavior of WinSCP (particularly the attempt to open the connection before the open
command is actually executed), I assume that you are using an old version of WinSCP that does not understand the /parameter
parameter yet. Make sure, you use the latest version of WinSCP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With