0

I have two AIX SFTP servers.

I want to move multiple files starting from word cash, e.g. cash2001.txt from one server to another using an sftp script and then want to delete the successfully moved files from the original server.

I have tried blow script but its not working

sftp -P 10022 EUSER_20233@11.214.6.920 <<EOF 
put /data/sftp/current/cash* 
exit
rm /data/sftp/current/cash* 
EOF
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

0

As the rm should be deleting local files, you must execute it in shell, not in sftp:

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

You may want to improve your code to delete the files, when the transfer succeeds only. Based on How to confirm SFTP file delivery?, you can do (in bash, I do not know 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
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992