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

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 errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option 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"
# Connect
open sftp://user:password@example.com/
# Change remote directory :%1% is passed-in parameter
cd  %1%
# Force binary mode transfer
option 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.txt
rm %3%
# Disconnect
close
# Exit WinSCP
exit
#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

setlocal
set LogPath=.\
set LogFileExt=.log
set LogFileName=Daily Backup%LogFileExt%
::use set MyLogFile=%date:~4% instead to remove the day of the week
set MyLogFile=%date%
set MyLogFile=%MyLogFile:/=-%
set MyLogFile=%LogPath%%MyLogFile%_%LogFileName%
If NOT Exist "%MyLogFile%" goto:noseparator
Echo.>>"%MyLogFile%"
Echo.===================>>"%MyLogFile%"
:noseparator
echo.%Date% >>"%MyLogFile%"
echo.%Time% >>"%MyLogFile%"
:startbatch
D:\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"



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值