7

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

1
  • 1
    Not sure you still need this information but the proper syntax in the winscp script file would be %1% and not %1. Commented Mar 27, 2013 at 3:19

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for your reply. But the "/parameter" and "%1%" didn't work for me.
I would try /parameter=param1 or just param1
4

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/

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.