成功上传到 SFTP 服务器后删除本地 AIX 文件

Delete local AIX files after a successful upload to an SFTP server

我有两个 AIX SFTP 服务器。

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

我试过 blow 脚本,但它不起作用

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

由于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* 

您可能需要改进代码以仅在传输成功时删除文件。基于,你可以这样做(在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