WinSCP command to connect to FTP server to get/put files

来源:互联网 发布:java 加载 xml 编辑:程序博客网 时间:2024/04/29 02:08

reference :

http://winscp.net/eng/docs/commandline#scripting

http://marionote.wordpress.com/2009/12/12/winscp-script-sample/

http://toastergremlin.com/?p=371

http://winscp.net/tracker/show_bug.cgi?id=197

http://winscp.net/forum/viewtopic.php?t=7960


1.FTP connection and operation : FTPscripts.txt

# Automatically abort script on errorsoption batch abort# Disable overwrite confirmations that conflict with the previousoption confirm off# Connect using a password# open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"# Connectopen sftp://user:password@example.com/# Change remote directory :%1% is passed-in parametercd  %1%# Force binary mode transferoption transfer binary# Download file abc.txt  to the local directory d:\abc\  : "get abc.txt d:\abc\" get %3% %2%# If you want to rename/remove the remote filename after uploading:#mv %3% aa.txtrm %3%# Disconnectclose# Exit WinSCPexit#pause

2.batch script :  GetDataFileFromFTPServer.bat

D:\zkoo\winscp553\winscp.exe /script=D:\xding\WINSCPscripts\FTPscripts.txt /parameter """/DCCEU/TX EU/BIN/TMS Call Update/"""  C:\SSIS\TMSCallUpdate\ TmsCallUpdate*.csv /log=D:\xding\WINSCPscripts\aa.log
1) 3 parameters here :

%1% :  remote folder  -  """/DCCEU/TX EU/BIN/TMS Call Update/""", there is space, so use 3 quotes. don't know why???

%2% : destination folder   -  C:\SSIS\TMSCallUpdate\

%3% : download file name    - TmsCallUpdate.csv

2)/log=D:\xding\WINSCPscripts\aa.log

  sample  to write to dynamic log file: testLog.bat

setlocalset LogPath=.\set LogFileExt=.logset LogFileName=Daily Backup%LogFileExt%::use set MyLogFile=%date:~4% instead to remove the day of the weekset MyLogFile=%date%set MyLogFile=%MyLogFile:/=-%set MyLogFile=%LogPath%%MyLogFile%_%LogFileName%If NOT Exist "%MyLogFile%" goto:noseparatorEcho.>>"%MyLogFile%"Echo.===================>>"%MyLogFile%":noseparatorecho.%Date% >>"%MyLogFile%"echo.%Time% >>"%MyLogFile%":startbatchD:\zkoo\winscp553\winscp.exe /script=TMSCallUpdateDataFile_FTP.txt /log="%MyLogFile%"

3.command line  to replace the above

D:\zkoo\winscp553\winscp.exe /command "open sftp://name:password@IPaddress" "cd  /FTP_DXY" "option ""transfer binary""" "get 1234*.txt D:\xding\ftp_dxy\ /log="D:\winscp.log"" "close" "exit"



0 0
原创粉丝点击