Configure WinSCP to upload automatically to SFTP

I needed to automate the upload of csv files to an SFTP server for print fulfilment. It was a bit trickier than I thought it would be so I recorded what I did in case I need to do it again someday.


1)     Download and install WinSCP from here: http://winscp.net


2)     Create a folder where files will be uploaded from and a sub folder called Archive


3)     Open WinSCP go to Options Select Storage and Set Configuration Storage to INI file (WinSCP.ini), close WinSCP.


4)     Add a the PATH to the WinSCP install folder in the Environment Variables


5)     Create a file in the upload folder called SftpScript.txt


6)     Create a .cmd file and add the following command, modify the path to SftpScript.txt


      winscp.com /console /script=C:FilesPrintFulfilmentSftpScript.txt >> SftpUpload.log


7)     Add the following code to SftpScript.txt, update the parameters highlighted in red.


 


# Automatically answer all prompts negatively not to stall the script on errors


option batch on


 


# Disable overwrite confirmations that conflict with the previous


option confirm off


 


# Connect using a password


open user:password@ftp.somewhere.com


 


# Force binary mode transfer


option transfer binary


 


# Change to home directory


cd


 


# Upload the file to current working directory


put C:FilesPrintFulfilment*.csv


 


# Disconnect


close


# Exit WinSCP


Exit


 


8)     To prevent the same file being uploaded next time the command runs add the following to the .cmd File, updating the file mask and archive folder path.


 


MOVE *.csv C:FilesPrintFulfilmentArchive