Friday, January 28, 2011

WinSCP scripting example

From here it's very easy: http://marionote.wordpress.com/2009/12/12/winscp-script-sample/

"c:\Program Files\WinSCP3\WinSCP.exe" /script=c:\winscpscript\testscript.txt /log=c:\winscpscript\log.txt

Then, create a script file (in this example, c:\winscpscript\testscript.txt.)
# Execute with winscp.exe /script=this_filename /log=logfile.txt
option batch abort
option confirm off
# Use the ip address of your SFTP server, instead of 127.0.0.1
open sftp_login_name:the_password@127.0.0.1

#In order to "cd" or "lcd", use these lines.
cd server_side_directory
lcd c:\client_side_directory

# Normal GET
get Get_This_File

# If you want to save as another filename:
get Get_This_File Get_This_File_local

# If you want to remove the remote file after downloading:
get -delete Get_This_File c:\client_side_directory\Get_This_File_local

# Upload sample script line
put upload_this_file remote_filename

# If you want to rename the remote filename after uploading:
mv remote_filename remote_filename_renamed

exit

5 comments:

Anonymous said...

hi, may I know how can I capture or get the script exit code? I would like to keep record of those files uploading success or not in a log. but I don't know hot to get it.

theborisedu said...

well the log is set in the beginning for this example and you can see all the login related info there, it shows the sync between the servers in this log but if you want more logging options try this link http://winscp.net/eng/docs/logging_xml

in the post example the log is located here c:\winscpscript\log.txt

if you want me to make another post about this log features you asked I can try to analyse the documentation for you.

Did that help?

Anonymous said...

This is MOST helpful--if the WinSCP site said anything about the log option they didn't make it clear for the newbie. I'm hoping that you can tell us how we can programatically capture the status codes that WinSCP writes during the execution of the script? Such as (as a result of an "ls filename" command), Status code: 1 if file is found, Status code: 2 if it isn't found?

alexsts said...

I do not know what the hek video codec do you have but your watch it link raised all security in our building.
Can you replace that video with something which can be played over windows based player without any additional codecs?

theborisedu said...

There's no video in this post