【问题标题】:Files are not present in SFTP directory after upload using WinSCP使用 WinSCP 上传后文件不存在于 SFTP 目录中
【发布时间】: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


【解决方案1】:

你的脚本有点意思。

如果您想要一个将所有 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?

【讨论】:

  • 太棒了,非常感谢!如果一切正常,我该如何有条件地删除(本地文件)?
  • put -delete 仅在每个文件成功上传后才会删除它们。还是您要上传所有文件,等所有文件都上传后才全部删除?
  • 没关系,越简单:) 那你写的就够了?我马上去试试
  • 非常感谢 Martin,你为我节省了很多时间寻找错误的方向。我欠你一个人情 !祝你好运。 Děkuji vám moc ;)
  • 完成!再次感谢;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-26
  • 1970-01-01
  • 2023-03-18
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多