FTP Transfer Concurrent Program

Submitted by code_admin on Wed, 07/11/2018 - 19:49

ftp_transfer.prog

  1. #!/bin/sh
  2. # xxgc_ftp_transfer2.prog v1.0 Thur 4 Sep 2008
  3. # Author: Robert Metcalf
  4. #
  5. # 1.0   initial version
  6. #Executable: XXGCFTPTRANS2
  7. #CR: Greenwich FTP transfer Process 2
  8. # $0 - Shellscript name
  9. # $1 - Oracle username/password
  10. # $2 - User_id
  11. # $3 - Oracle Applications username
  12. # $4 - Concurrent request id
  13.  
  14. LOGFILE=$COMMON_TOP/admin/$APPLLOG/l$4.req
  15.  
  16. OUTFILE=$COMMON_TOP/admin/$APPLOUT/o$4.out
  17. if [ $APPCPNAM = 'USER.REQID' ]; then
  18.         #Output file name is in the format USERNAME.######
  19.         #See bottom of page 8
  20.         OUTFILE=$COMMON_TOP/admin/$APPLOUT/$3.$4
  21. fi
  22.  
  23. #$5 = src dir (full path from root with trailing slash)  '/apps11i/dev/devcomn/admin/out/DEV_gchrdev/'
  24. #$6 = src file name (File name to transfer) 'o2992771.out'
  25. #$7 = Dest DIR (where to go) 'BST, Finance, HR'
  26. #$8 = dest file name
  27. #$9 = FTP Host Name:::FTP Username :::FTP Password
  28.  
  29. I_SRC_DIR=$5
  30. I_SRC_FIL=$6
  31. I_DEST_DIR=$7
  32. I_DEST_FIL=$8
  33. I_FTP_HOST=`echo $9 | awk -F ::: '{print $1}'`
  34. I_FTP_USER=`echo $9 | awk -F ::: '{print $2}'`
  35. I_FTP_PASS=`echo $9 | awk -F ::: '{print $3}'`
  36.  
  37. echo "xxgc_ftp_transfer2.prog running" >> $LOGFILE
  38. echo "script being run as:" >> $LOGFILE
  39. whoami >> $LOGFILE
  40. echo "TWO_TASK: " $TWO_TASK >> $LOGFILE
  41. echo "Source Dir: " $I_SRC_DIR >> $LOGFILE
  42. echo "Source File name: " $I_SRC_FIL >> $LOGFILE
  43. echo "Dest Dir: " $I_DEST_DIR >> $LOGFILE
  44. echo "Dest File name: " $I_DEST_FIL >> $LOGFILE
  45. echo "FTP Host: " $I_FTP_HOST >> $LOGFILE
  46. echo "FTP User: " $I_FTP_USER >> $LOGFILE
  47. echo "FTP Pass: ******" >> $LOGFILE
  48. echo "See output for processing messages" >> $LOGFILE
  49.  
  50. echo "xxgc_ftp_transfer2.prog running" >> $OUTFILE
  51. echo "script being run as:" >> $OUTFILE
  52. whoami >> $OUTFILE
  53. echo "TWO_TASK: " $TWO_TASK >> $LOGFILE
  54. echo "Source Dir: " $I_SRC_DIR >> $OUTFILE
  55. echo "Source File name: " $I_SRC_FIL >> $OUTFILE
  56. echo "Dest Dir: " $I_DEST_DIR >> $OUTFILE
  57. echo "Dest File name: " $I_DEST_FIL >> $OUTFILE
  58. echo "FTP Host: " $I_FTP_HOST >> $OUTFILE
  59. echo "FTP User: " $I_FTP_USER >> $OUTFILE
  60. echo "FTP Pass: ******" >> $OUTFILE
  61.  
  62. #Check TWO_TASK is set correctly
  63. if [ "E" = E$TWO_TASK  ]; then
  64.         echo "ERROR - TWO_TASK is not set" >> $OUTFILE
  65.         echo "TWO_TASK must be set for this command to run" >> $OUTFILE
  66.         exit 1
  67. fi
  68. loc_ok=0
  69. for X in "PROD" "TEST" "SUPPORT" "DEV" "TRAIN"
  70. do
  71.         if [ $X = $TWO_TASK ]; then
  72.                 loc_ok=1
  73.         fi      
  74. done
  75. if [ $loc_ok = 0 ]; then
  76.         echo "TWO_TASK is not correctly set." >> $OUTFILE
  77.         echo "TWO_TASK = $TWO_TASK" >> $OUTFILE
  78.         exit 1
  79. fi
  80.  
  81. TMP=`echo $I_SRC_DIR | sed -n 's/\(^.[^$]*\)\(.\{1\}$\)/\2/p'`
  82. if [ $TMP != "/" ]
  83.         then
  84.         echo "Source dir dosn't end with / (" $I_SRC_DIR ")" >> $OUTFILE
  85.         exit 1
  86. fi              
  87. TMP=`echo $I_SRC_DIR |cut -c1-1`
  88. if [ $TMP != "/" ]
  89.         then
  90.         echo "Source dir dosn't start with / (" $I_SRC_DIR ")" >> $OUTFILE
  91.         exit 1
  92. fi            
  93.  
  94. if [ "PROD" != $TWO_TASK ]
  95.         then
  96.         I_DEST_FIL="TEST_FILE_"$TWO_TASK"_"$I_DEST_FIL
  97.         echo "Non prod, changed Dest File name to: " $I_DEST_FIL >> $OUTFILE
  98. fi
  99.  
  100. if [ ! -d $I_SRC_DIR ]; then
  101.         echo "ERROR - Can't find the source directory (" $I_SRC_DIR ")" >> $OUTFILE
  102.         exit 1
  103. fi
  104.  
  105. if [ ! -f $I_SRC_DIR$I_SRC_FIL ]; then
  106.         echo "Source file does not exist (" $I_SRC_DIR$I_SRC_FIL ")" >> $OUTFILE
  107.         exit 1
  108. fi
  109.  
  110. loc_ok=0
  111. for X in "BST" "Finance" "HR"
  112. do
  113.         if [ $X = $I_DEST_DIR ]; then
  114.                 loc_ok=1
  115.         fi      
  116. done
  117. if [ $loc_ok = 0 ]; then
  118.         echo "Dest dir must be one of ""BST"" ""Finance"" ""HR""" >> $OUTFILE
  119.         echo "Dest dir = $I_DEST_DIR" >> $OUTFILE
  120.         exit 1
  121. fi
  122. I_DEST_DIR=$I_DEST_DIR "/"
  123.  
  124. echo "Checks passed, attempting transfer..." >> $OUTFILE
  125.  
  126. #************************************************END OF CHECKS ACTUALL CODE TO DO TRANSFER*****************************
  127.  
  128. $XXGC_TOP/bin/ftp_call2.sh $I_SRC_DIR $I_SRC_FIL $I_FTP_HOST $I_DEST_DIR $I_FTP_USER $I_FTP_PASS $I_DEST_FIL >> $OUTFILE
  129.  
  130. TMP=`grep "Not connected" $OUTFILE`
  131. if [ "E" != E$TMP  ]; then
  132.         echo "ERROR - is the hostname correct?" >> $OUTFILE
  133.         exit 1
  134. fi
  135. TMP=`grep "Login failed" $OUTFILE`
  136. if [ "E" != E$TMP  ]; then
  137.         echo "ERROR - the FTP login failed. Is the username and password correct?" >> $OUTFILE
  138.         exit 1
  139. fi
  140. TMP=`grep "File not found" $OUTFILE`
  141. if [ "E" != E$TMP  ]; then
  142.         echo "ERROR - File not found - Transfer failed" >> $OUTFILE
  143.         exit 1
  144. fi
  145. TMP=`grep "No such file or directory" $OUTFILE`
  146. if [ "E" != E$TMP  ]; then
  147.         echo "ERROR - No such file or directory - Transfer failed" >> $OUTFILE
  148.         exit 1
  149. fi
  150. TMP=`grep "Cannot create a file when that" $OUTFILE`
  151. if [ "E" != E$TMP  ]; then
  152.         echo "ERROR - Can't create file. Try deleting contents or ftp dir - Transfer failed" >> $OUTFILE
  153.         exit 1
  154. fi
  155. TMP=`grep "250 RNTO command successful" $OUTFILE`
  156. if [ "E" = E$TMP  ]; then
  157.         echo "ERROR - No sucessful rename found - Transfer failed" >> $OUTFILE
  158.         exit 1
  159. fi
  160. TMP=`grep "426 Connection closed; transfer aborted" $OUTFILE`
  161. if [ "E" != E$TMP  ]; then
  162.         echo "ERROR - The transfer aborted. This could be because there is not enough disk space availible" >> $OUTFILE
  163.         echo "on the ftp drive" >> $OUTFILE
  164.         echo "The FTP drive should be used as a transfer location only, not to store files" >> $OUTFILE
  165.         echo "Clear down the directory and retry" >> $OUTFILE
  166.         echo "If this does not work call system support" >> $OUTFILE
  167.         exit 1
  168. fi
  169.  
  170. echo "FTP Transfer operation completed sucessfully" >> $OUTFILE
  171.  
  172. exit 0

ftp_call2.sh

  1. #echo $username $password $target_server
  2. # start the copy
  3. cd $1
  4. USER=$5
  5. PASSWD=$6
  6. ftp -i -n -d $3 <<SCRIPT
  7. user $USER $PASSWD
  8. verbose
  9. cd $4
  10. delete "$2"
  11. delete "$7"
  12. put "$2"
  13. rename "$2" "$7"
  14. quit

SCRIPT
Misc
Note: Create this file in $XXGC_TOP/bin as ftp_transfer.prog
Then run symbolic link code

RJM Article Type
Quick Reference