Batch file 使用WinSCP上载后,SFTP目录中不存在文件
我需要一个脚本,将文件复制到一个SFTP服务器使用WinSCPBatch file 使用WinSCP上载后,SFTP目录中不存在文件,batch-file,sftp,winscp,Batch File,Sftp,Winscp,我需要一个脚本,将文件复制到一个SFTP服务器使用WinSCP 连接 复制文件 如果复制确定,则删除本地文件 断开 到目前为止,我的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 e
- 连接
- 复制文件
- 如果复制确定,则删除本地文件
- 断开
# 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:password@example.com
# 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
@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"
到目前为止,我的bat文件:
# 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:password@example.com
# 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
@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"
到目前为止,它没有上传文件,但会删除它们。您的脚本有点道理 如果您想要一个简单的脚本,将所有
Y:\*.txt
文件移动到/tracks
,将所有Y:\*.tar gz*
文件移动到/tracksm
,请将打开
命令后的所有脚本替换为:
put -delete Y:\*.txt /tracks/
put -delete Y:\*.tar-gz* /trackm/
exit
看
虽然看起来,虽然最初的剧本相当丑陋和低效,但它可能完成了它的工作 根本问题是,服务器可能会对上载的文件进行一些处理,并在处理后删除或移开这些文件 这是处理文件的服务器的常见行为(与存储文件相反)。
请参阅WinSCP常见问题解答
put-delete
如果文件以前未上载,则从不删除该文件。向我们展示一个会话日志文件(/log=…
命令行开关)。这里是:https://we.tl/t-xorwn5qd7ii如果您引用“Aucun-fichier correspondantá.txt'trouve.”*->该错误消息显然来自get*.txt
而不是来自put-delete“Y:\*.txt”
-WinSCP实际上看不到任何put-delete“Y:\*.txt”
命令。确保执行问题中发布的脚本文件的版本。没错,我执行的文件有点不同,但唯一的区别是它的开头(在选项“确认关闭”之前):#自动消极地回答所有提示,不要暂停#错误上的脚本选项批处理-这是我得到的日志(看起来相同):https://we.tl/t-q3t2GtwhefI修改了我以前的一点评论,还有新的日志非常棒,非常感谢!我如何有条件地删除(本地文件)如果上传的一切正常?put-delete
只在成功上传后删除每个文件。或者你想上传所有文件,只在上传完所有文件后删除所有文件吗?没关系,越简单:)那么你写的就够了?我马上就去试试。谢谢马丁,你帮我省了一大笔钱总有一天我会朝错误的方向看。我欠你一个人情!祝你一切顺利。Děkuji vám moc;)完成!再次感谢;)