1. grep -e ^lcd -e ^cd -e ^put -e ^delete -e ^get -e ^quit $ftp_cmd_file | sed s/^delete/rm/ | awk '!/^rm/ {print $0} /^rm/ {print $0"\""}' > $sftp_cmd
This extracts all ftp commands, excluding host and login info, and stores them into a temp sftp script. The ftp "delete" command is replaced by sftp "rm" command. In addition, for DELETE operation, PS leaves off a closing ", so it looks like this
delete "XXXXXX.YYY
FTP does not complain it, but SFTP is more strict in syntax and will cause an error. The command changes it to
rm "XXXXXX.YYY"
For PUT operation, PS inserted a "mkdir" command. This will cause SFTP to error in batch mode. So this command is not picked up by the script, just verify the directory exists beforehand.
2. $SFTP_CMD -b $sftp_cmd `grep ^user $ftp_cmd_file|awk '{print $2}'`@`grep ^open $ftp_cmd_file|awk '{print $2}'` 1>$sftp_log 2>&1
($SFTP_CMD = sftp executable)
This executes SFTP in batch mode, with host name and login info from the original ftp script. Password is not needed, as it will be authenticated by Public Key.
I embedded a sleep command in SFTP to get a view at the process tree for this
- 24781020 - An App Server instance handles the PS connection and peforms
- 15798308 - App Server instances spwans a shell & executes ftpunx script
- 19480650 - ftpunx script runs sftp command
- 14291166 - sftp run ssh to handle file transfer
- 2396354 - ssh exeutes a OS command
Change Peoplesoft FTP to SFTP - Part 1 | Change Peoplesoft FTP to SFTP - Part 3