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

问题描述 投票:1回答:1

我需要一个脚本,使用WinSCP将文件复制到SFTP服务器。

  • 复制文件
  • 如果复制ok,则删除本地文件
  • 断开

到目前为止我的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"

到目前为止,它不会上传文件,但会删除它们。

batch-file sftp winscp
1个回答
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?

© www.soinside.com 2019 - 2024. All rights reserved.