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] -

Wednesday, January 28, 2009 7:16:04 AM (GMT Standard Time, UTC+00:00)
Quite useful. But how do I schedule the above activity daily. I want this command to upload file daily to remote location at 6 PM. Thanks in advance
Thursday, January 29, 2009 11:04:14 PM (GMT Standard Time, UTC+00:00)
I used a scheduled task to call .cmd file
Charlie
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
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: 169
This Year: 11
This Month: 2
This Week: 0
Comments: 77
Themes
Pick a theme:
All Content © 2010, Charlie Barker
DasBlog theme 'Business' created by Christoph De Baene (delarou)