【问题标题】:Delete local AIX files after a successful upload to an SFTP server成功上传到 SFTP 服务器后删除本地 AIX 文件
【发布时间】:2021-06-05 16:41:58
【问题描述】:

我有两个 AIX SFTP 服务器。

我想从 word cash 开始移动多个文件,例如cash2001.txt 使用 sftp 脚本从一台服务器到另一台服务器,然后想要从原始服务器中删除成功移动的文件。

我尝试过打击脚本,但它不起作用

sftp -P 10022 EUSER_20233@11.214.6.920 <<EOF 
put /data/sftp/current/cash* 
exit
rm /data/sftp/current/cash* 
EOF

【问题讨论】:

    标签: sftp aix


    【解决方案1】:

    由于rm应该是删除本地文件,所以必须在shell中执行,而不是sftp:

    sftp -P 10022 EUSER_20233@11.214.6.920 <<EOF 
    put /data/sftp/current/cash* 
    exit
    EOF
    rm /data/sftp/current/cash* 
    

    您可能希望改进代码以删除文件,仅当传输成功时。基于How to confirm SFTP file delivery?,你可以这样做(在bash中,我不知道AIX):

    sftp -P 10022 EUSER_20233@11.214.6.920 -b - <<EOF 
    put /data/sftp/current/cash* 
    exit
    EOF
    
    if [ $? -eq 0 ]
    then
        rm /data/sftp/current/cash* 
    fi
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2023-03-12
      • 2016-01-28
      • 2019-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      相关资源
      最近更新 更多