获取WinSCP
windows上装上Winscp程序,使用这个程序通过sftp协议把本地的文件传输到linux服务器上。
编写脚本
# 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 | [;...]
# option include clear | [;...]
# open [ sftp|ftp|scp:// ][ [ :password ] @ ] [ : ]
# open user:password@example.com
# Connect
open scp://root:name@192.168.1.1:22
#open [scp:// ][ [ :password ] @ ] [ : ]
# Change remote directory
# cd /home/user #远程工作目录
cd /tmp
# Change local directory
# set to Self's working dir
#lcd D:\XXXXXX.bin #本地工作目录
put C:\Users\Administrator\Desktop\XXXXXXXXX.bin
# 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 | [;...]
# option include /2008-*-*/;/2009-*-*/;/2010-*-*/;/2011-*-*/;/2012-*-*/;/2013-*-*/
# synchronize local|remote|both [ [ ] ]
# 传输方式:Local为远程至本地,remote为本地到远程,both双向传输
#使用关键字synchronize的话,将会同步本地目录下的文件至远程目录
#synchronize remote
remote
# Disconnect
close
# Exit WinSCP
exit
说明:
我这里需要传送的文件只有一个二进制文件,所以后面不需要同步,如果需要操作整个目录的文件可以用synchronize remote。
执行脚本
在Windows系统中运行cmd,通过WinSCP.exe执行这个脚本即可。
https://blog.csdn.net/shufac/article/details/51966276