我需要一个脚本,使用WinSCP将文件复制到SFTP服务器。
到目前为止我的txt文件:
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# open user:[email protected]
# Connect
open sftp://***:***@***.fr/ -hostkey=*
# Force binary mode transfer
option transfer binary
# Interface 1
cd /tracks
lcd "Y:\"
#Copie des données en local
get *.txt
#Envoie de données sur le serveur
put *.*
#Effacement des données
put -delete "Y:\*.txt"
# Interface 2
cd /trackm
lcd "Y:\"
#Copie des données en local
get *.tar-gz*
#Envoie de données sur le serveur
put *.*
#Effacement des données
put -delete "Y:\*.tar-gz*"
#Disconnect
#close
#Exit WinSCP
#exit
我的bat文件到目前为止:
@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"
到目前为止,它不会上传文件,但会删除它们。
你的脚本有点意义。
如果你想要一个简单的脚本将所有Y:\*.txt
文件移动到/tracks
并将所有Y:\*.tar-gz*
文件移动到/tracksm
,请在open
命令之后替换所有脚本:
put -delete Y:\*.txt /tracks/
put -delete Y:\*.tar-gz* /trackm/
exit
见documentation of put
command。
虽然看起来虽然原始剧本非常丑陋且效率低下,但它可能完成了它的工作。
根本问题是您的服务器可能会对上传的文件进行一些处理,并在处理完文件后删除或移走文件。
这是处理文件的服务器的常见行为(与存储文件相反)。 请参阅WinSCP常见问题解答Why is uploaded file not showing in a remote directory or showing with a different name?