- 论坛徽章:
- 15
|
利用Winscp软件同步本地或远程的文件(一)
http://www.cnblogs.com/anny-1980/articles/1064167.html
有的时候我们会将远程FTP上的文件同步到本地,通过运行我们编写的程序对文件进行一系统的操作,会产生一些输出文件,然后再将处理后的文件同步到远程FTP上.
针对上述中的远程文件同步到本地或本地文件同步到远程FTP上的情况,我们可以利用Winscp软件,执行一系列的FTP命令.winscp软件可在网上下载.
winscp的命令范例:
# winscp.exe /console /script=sample.txt
# Automatically answer all prompts negatively not to stall
# the script on errors
# option echo on|off
option echo off
# option batch on|off|abort|continue
option batch on
# option confirm on|off
option confirm off
# option transfer binary|ascii|automatic
# option synchdelete on|off
# option exclude clear | <mask>[;<mask2>...]
# option include clear | <mask>[;<mask2>...]
# open [ sftp|ftp|scp:// ][ <user> [ :password ] @ ] <host> [ :<port> ]
# open user:password@example.com
# Connect FTP地址
open ftp://用户名:密码@outftp.test.com:21
# Change remote directory
# cd /home/user 如果同步到远程FTP时,可用此命令转到远程某个目录下.
# Change local directory
# set to Self's working dir 设置需要同步到远程FTP的本地文件目录
lcd D:\Temp\Test_Ftp
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
# get examplefile.txt d:\
# option synchdelete on|off
option synchdelete off
# option include clear | <mask>[;<mask2>...]
# option include /2008-*-*/;/2009-*-*/;/2010-*-*/;/2011-*-*/;/2012-*-*/;/2013-*-*/
# synchronize local|remote|both [ <local directory> [ <remote directory> ] ] 从远程同步到本地用Local;从本地同步到远程用Remote
synchronize local
# Disconnect
close
# Exit WinSCP
exit
将上述脚本存成sample.txt文件,然后通过winscp.exe /console /script=sample.txt 命令执行文件同步操作.
我们通常可以将此命令写到批处理.bat文件中,将要运行的用户编写的本地.ext程序也写入批处理文件中,然后放到控制面板->计划任务中,这样程序可定时执行,不需要用户再反复从远程取文件,执行程序,再上传到远程这一系列操作. |
|