[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: Using FTP commands in SQR



Yes it is.  Here's some sample code that I'm using to get a file from a
remote server, and the process is basically the same to PUT it as well.  The
sqr gets the user and password info from the UNIX .netrc file

!***********************************************************************
Begin-PROCEDURE Build-FTP-File          !Create the UNIX script to be run on
remote FTP Server
!***********************************************************************

     Let $Cmd_Bank     =    $Bank
     lowercase $Cmd_Bank
     Let $FTP_Cmd_File =    $FTP_Cmd_File||'_'||$Cmd_Bank ||'.cmd'

     Let $Msg = 'FTP Cmd File Name  :'||$FTP_Cmd_File
       Do Print-Log
     Let $Msg = ' '
       Do Print-Log

     Let $Line1     = 'ftp -iv '||$Source_File_Server||' <<EOF!!'
     Let $Line2     = 'ascii'
     Let $Line3     = 'prompt'
     Let $Line4     = 'lcd '||$Target_File_Directory
     Let $Line5     = 'rm '||$Target_File_Name
     Let $Line6     = 'mget '||$TWC_File_Name_Imp ||' '||$Target_File_Name
     Let $Line7     = 'quit'
     Let $Line8     = 'EOF!!'

     Do Open-FTP-File

     If #Open_Stat = 0
          Do Write-FTP-File
     End-If

End-PROCEDURE

!***********************************************************************
Begin-PROCEDURE Open-FTP-File
!***********************************************************************

     Let $Error_Flag = 'N'

     Open $FTP_Cmd_File as 1 For-Writing Record=80 Status=#Open_Stat
     If #Open_stat <> 0
          Let $Error_Flag     = 'Y'
          Let #Return-Status  = 99
          Move #Return-Status to $Return-Status
          Move #Open_Stat     to $Open_Stat 99
          Let $Msg = 'FATAL ERROR - UNABLE TO OPEN FTP CMD FILE FOR WRITING,
'
          Let $Msg = $Msg||'Process Terminated'
            Do Print-Log
          Let $Msg = 'FTP Cmd File Open Status     :'||$Open_Stat
            Do Print-Log
          Let $Msg = ' '
            Do Print-Log
     End-If

End-PROCEDURE

!***********************************************************************
Begin-PROCEDURE Write-FTP-File
!***********************************************************************

     Write 1 From $Line1
     Write 1 From $Line2
     Write 1 From $Line3
     Write 1 From $Line4
     Write 1 From $Line5
     Write 1 From $Line6
     Write 1 From $Line7
     Write 1 From $Line8

     Close 1

 End-PROCEDURE

!***********************************************************************
Begin-PROCEDURE Execute-Chmod-File
!***********************************************************************

     Let $Chmod_Cmd_File = $Chmod_Cmd_file||'_'||$Cmd_Bank||'.cmd'

     Let $Msg = 'Chmod Cmd File Name         :'||$Chmod_Cmd_File
       Do Print-Log
     Let $Msg = ' '
       Do Print-Log

   Open $Chmod_Cmd_File as 1 For-Reading Record=80 Status=#Open_stat
     If #Open_Stat <> 0
          Move #Open_Stat to $Open_Stat 99
          Let $Msg = 'WARNING:  Unable to Open Chmod Cmd File'
            Do Print-Log
          Let $Msg = 'Chmod Cmd File Open Status       :'||$UNIX_Stat
            Do Print-Log
          Let $Msg = ' '
            Do Print-Log
     Else
          Let $UNIX_Cmd_File = $chmod_Cmd_File
            Do Execute-UNIX-Call

          If #UNIX_Stat <> 0
               Let $Msg = 'WARNING:  Unable to Execute Chmod Cmd File'
                 Do Print-Log
               Let $Msg = 'Chmod Cmd File Status       :'||$UNIX_Stat
                 Do Print-Log
               Let $Msg = ' '
                 Do Print-Log
          End-If
     End-If
     close 1
End-PROCEDURE

!***********************************************************************
Begin-PROCEDURE Execute-FTP-File
!***********************************************************************

     Let $Msg = '-------- FTP Command File Execution - Start --------'
          Display $Msg
     Let $Msg = ' '
          Display $Msg

     Let $UNIX_Cmd_File = $FTP_Cmd_File
          Do Execute-UNIX-Call

     Let $Msg = ' '
       Display $Msg
     Let $Msg = '--------FTP Command File Execution - End --------'
       Display $Msg
     Let $Msg = ' '
       Display $Msg

     If #UNIX_Stat <> 0
          Let $Error_Flag = 'Y'
          Let #Return-Status = 99
          Move #Return-Status to $Return-Status
          Let $Msg = 'FATAL ERROR - UNABLE TO EXECUTE FTP CMD FILE, PROCESS
TERMINATED'
            Do Print-Log
          Let $Msg = 'FTP Cmd File Status         :'||$UNIX_Stat
            Do Print-Log
          Let $Msg = ' '
            Do Print-Log
     End-If

End-PROCEDURE

!***********************************************************************
Begin-PROCEDURE Execute-UNIX-Call       !Run the FTP Script
!***********************************************************************

     Call System Using $UNIX_Cmd_File  #UNIX_Stat
     Move #UNIX_stat to $UNIX_Stat 99

End-PROCEDURE



Jim McKeever
Sr. Programmer/Analyst - New Technology
Phone: (303) 705-4534
E-Mail:   james.mckeever@twcable.com OR
             JMcKeever0953@aol.com