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:[email protected]/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Connect
open sftp://user:[email protected]/
# 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"



你可能感兴趣的:(技术)