ReceiveFTPFile(Asynchronous) and AbortFTP() usage

Just starting out? Need help? Post your questions and find answers here.
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

ReceiveFTPFile(Asynchronous) and AbortFTP() usage

Post by HwyStar »

I have had some problems twice in the last two months where a remote ftp server has been restarted out from under me during a file transfer; which ended up on my server locking up on a disconnected and now corrupt file.

ReceiveFTPFile() has an Asynchronous feature and "I think" that AbortFTP() needs to be used to terminate the session on an ftp failure.

Can you check my code below to make sure my logic makes sense for ReceiveFTPFile() and AbortFTP() please? The help text does not give us an example of how to use ReceiveFTPFile() in Asynchronous mode.

Code: Select all

      While NextFTPDirectoryEntry(0)
        
        If FTPDirectoryEntryType(0) = #PB_FTP_Directory
          Continue;
        EndIf  
        
        ;Added the Select Result code block below: 01/12/18 RJH
        Repeat 
          
          Result = ReceiveFTPFile(0, FTPDirectoryEntryName(0), localchdir$ + "\" + FTPDirectoryEntryName(0), #True) ; True switch added...
          Select Result
          Case #PB_FTP_Started
          Case #PB_FTP_Error
            AbortFTPFile(0)                                                                                         ; AbortFTPFile Transfer on failure
            LogFile("#PB_FTP_Error with connection to remote file: " + FTPDirectoryEntryName(0))
            Break
            
          Case #PB_FTP_Finished
            LogFile("Copied remote file: " + FTPDirectoryEntryName(0))
            Files = Files + 1
            
            Result = DeleteFTPFile(0, FTPDirectoryEntryName(0))
            If Result = 0
              LogFile("Error deleting remote file: " + FTPDirectoryEntryName(0))
            Else
              LogFile("Deleted remote file: " + FTPDirectoryEntryName(0))
            EndIf   
            Break
            
          Default
            ;All is well!
          EndSelect
          Delay(1)

        ForEver
        Delay(100)    
        
      Wend
Thanks for your help!