【问题标题】:Download only new files with WinSCP使用 WinSCP 仅下载新文件
【发布时间】:2022-01-07 02:26:06
【问题描述】:

我目前正在编写一个 WinSCP 脚本,其目的是从 SFTP 服务器检索所有文件,然后将它们放在目标服务器中的指定位置(脚本所在的位置,仅供参考)。 是否有人检查文件是否已在目标服务器上传输?有的时候会覆盖吗?在那种情况下,这真的是一件坏事吗?在这种情况下,我猜如果目标服务器上已经存在该文件,我不希望发生任何事情。如果它不存在,那么我想继续转移。

您将在下面找到到目前为止编写的代码

# Automatically abort script on errors
option batch abort

# Disable overwrite confirmations that conflict with the previous
option confirm off 

# Connect using a password 
open sftp://SERVER@IP_ADDRESS:PORT -privatekey="PRIVATE_KEY" -hostkey="HOSTKEY" -passive=off 

# Change remote directory
cd in
cd DIRECTORY

# Force binary mode transfer
option transfer binary

# Get ALL files from the directory specified
get /*.csv* \\DIRECTORY

# Remove all .csv files
rm /*.csv

# Exit WinSCP
bye

非常感谢您的帮助,希望它足够清楚,否则请告诉我是否可以为您提供更多信息

【问题讨论】:

    标签: sftp file-transfer winscp


    【解决方案1】:

    最简单的解决方案是将-neweronly switch 添加到您的get command

    get -neweronly /*.csv \\DIRECTORY
    

    对于非常相似的结果,您也可以使用synchronize command

    synchronize local \\DIRECTORY / -filemask=*.csv
    

    另请参阅 Downloading the most recent file 上的 WinSCP 文章。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-23
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      相关资源
      最近更新 更多