Pages

Monday, June 8, 2009

Change Peoplesoft FTP to SFTP - Part 2

In the PS generated script, ftp?????_????.txt, it stores the host, login, cd, lcd, get/put/delete & quit commands. A single file is processed each time. Prior to doing sftp, the correct public/private keys need to be generated, known_host and authorized_keys must be set up for the ftp use account. Converting the script to run sftp is straightforward, in 2 steps:

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
This is all it takes to transfer a file using secured FTP with sftp. But this is just the beginning, to fully integrate with PS, the results must be "relayed" back to PS . This is done through examination of the SFTP log file. The technique I used is detailed in the next part.

Change Peoplesoft FTP to SFTP - Part 1 | Change Peoplesoft FTP to SFTP - Part 3