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.
- You want to automatic upload all files under C:\upload
- Download and install WinSCP. Assume you will install the program to C:\Program Files\WinSCP.
- Test the connectivity of WinSCP with the target server.
- Prepare your own batch job to manage files under c:\upload (i.e. add new files and/or remove old files)
- Create a WinSCP script file and save as c:\batch\ftpscript.txt
option batch abort
option confirm off
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.
- 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
- That’s all!