MarioNote

December 12, 2009

WinSCP Script – Sample

Filed under: Sample code — mariojump @ 12:00 am
Tags: ,

WinSCP has a scripting feature.
For example, if you create a batch file, which contains:

"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

Advertisements

2 Comments »

  1. Hello mario
    I just started using winscp i already have it working with a bat and txt files just like you but i nned an account logged in in order to the schedule apply correctly if i log out it doesnt work is there anuthing i need to do so i can leave my pc without an account logged in and my scriptings executing correctly????

    Thanks in advice
    Max

    Comment by Max — June 16, 2012 @ 5:03 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: