使用WinSCP上传后,文件不存在于SFTP目录中

时间:2018-09-06 09:14:23

标签: batch-file sftp winscp

我需要一个脚本,该脚本将使用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

到目前为止我的蝙蝠文件:

@echo off
"D:\WinSCP\WinSCP.com" /log="D:\logfile.log" /ini=nul /script="D:\script_test.txt"

到目前为止,它还没有上传文件,但是会删除它们。

1 个答案:

答案 0 :(得分: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?

相关问题