Bloggin in the UK RSS 2.0
 Monday, October 13, 2008

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:\Files\PrintFulfilment\SftpScript.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:\Files\PrintFulfilment\*.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:\Files\PrintFulfilment\Archive\

Monday, October 13, 2008 4:48:43 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -

Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010
Charlie Barker
Sign In
Statistics
Total Posts: 163
This Year: 5
This Month: 1
This Week: 1
Comments: 76
Themes
Pick a theme:
All Content © 2010, Charlie Barker
DasBlog theme 'Business' created by Christoph De Baene (delarou)