A very simple guide to automatic upload files using WinSCP

 

WinSCP is a very powerful SFTP/FTP client because it supports script.  It is very useful for using schedule job to upload/download files automatically.  It also have builtin file syncronization feature.  Below is a very minimistic example to automate file upload.

Objective

  1. You want to automatic upload all files under C:\upload

Preparation

  1. Download and install WinSCP.  Assume you will install the program to C:\Program Files\WinSCP.
  2. Test the connectivity of WinSCP with the target server.
  3. Prepare your own batch job to manage files under c:\upload (i.e. add new files and/or remove old files)
  4. Create a WinSCP script file and save as c:\batch\ftpscript.txt
    open sftp://<username>:<password>@<IP_or_hostname>
    option batch abort
    option confirm off
    lcd c:\upload
    cd /
    put *.*
    exit


    Description:
    1. open: Connect to the target server using URL.  In this example, sftp:// protocol is used.  You can use ftp:// instead.
    2. option batch abort and option confirm off are required for smooth batch operation without question asked.
    3. lcd: change local directory.  To change remote directory, use cd command
    4. put *.* will upload all files (including sub-directory).  WinSCP will handle binary or text mode automatically.  There is no need to manually change transfer mode.
  5. Create a Windows schedule (or any scheduler you want) to run the below command:
    "c:\Program Files\WinSCP\winscp.com" /script=c:\batch\ftpscript.txt /log=c:\batch\ftplog.txt
  6. That’s all!

Comments