【发布时间】:2019-02-11 12:20:41
【问题描述】:
我需要一个使用 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: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
到目前为止我的 bat 文件:
@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"
到目前为止,它还没有上传文件,而是删除了它们。
【问题讨论】:
-
put -delete永远不会删除一个文件,如果它之前没有上传过。向我们展示一个会话日志文件(/log=...命令行开关)。 -
这里是:https://we.tl/t-XOrwN5qD7I
-
如果您参考 "Aucun fichier 通讯员 à '.txt' trouvé."* -> 该错误消息显然来自
get *.txt而不是来自put -delete "Y:\*.txt"- WinSCP 实际上没有看到任何put -delete "Y:\*.txt"命令。确保执行您在问题中发布的脚本文件版本。 -
你说得对,我执行的文件有点不同,但唯一的区别是它的开头(在选项确认关闭之前):#自动否定所有提示,不要停止#脚本on errors option batch on - 这是我得到的日志(看起来一样):https://we.tl/t-q3t2Gtwhef
-
我修改了一点我之前的评论,有新的日志
标签: batch-file sftp winscp