GetFTPFile Method
Class: FTP_SERVICE
Description:Get file from the FTP Server
This method will bring a file from the FTP Server down to a location specified in lcLocalFile.
=
Object.GetFTPFile
Parameter
lcRemoteFile
Remote file name
Type Character
Direction Input
Name and Path of the file on the FTP Server to bring down.
This parameter cannot be empty.
lcLocalFile
Local file name
Type Character
Direction Input
Name and Path for the contents of the file to be stored in.
This parameter cannot be empty.
llFailIfExists
File exists flag
Type Boolean
Direction Input
.T. to fail if the local file exists. .F. to overwrite the local file.
lnFlag
The flags that indicate various options.
Type Numeric
Direction Input
Value is combined with FTP_SERVICE::nCachingType's value. If this parameter ommited, then default value is FTP_TRANSFER_TYPE_UNKNOWN. Can be one of the following:
ValueDescription
FTP_TRANSFER_TYPE_ASCIITransfers the file as ASCII.
FTP_TRANSFER_TYPE_BINARYTransfers the file as binary.
FTP_TRANSFER_TYPE_UNKNOWNDefaults to FTP_TRANSFER_TYPE_BINARY.
INTERNET_FLAG_TRANSFER_ASCIITransfers the file as ASCII.
INTERNET_FLAG_TRANSFER_BINARYTransfers the file as binary.
Assumed from MSDN.
Return value Boolean
Returns .T. if the function successfully copied the file from the FTP Server. Returns .F. if the operation failed.
Example
LOCAL loFTP SET PROCEDURE TO ftp.prg ADDITIVE loFTP=CREATEOBJECT('ftp_service') IF loFTP.OpenInternet("ABONNE", "PWD", "10.10.10.10", "21") IF loFTP.GetFTPFile("any.txt","local.txt") ?STRTRAN("File %File% downloaded","%File%","local.txt") ELSE ?loFTP.GetExtendedErrorCode(),loFTP.GetExtendedErrorMsg() ENDIF =loFTP.CloseInternet() ENDIF RELEASE PROCEDURE ftp.prg
See also
Expand/Collapse source code of procedure GetFTPFile Source Code
      LPARAMETERS INP lcRemoteFile, INP lcLocalFile, INP llFailIfExists, INP lnFlag
      LOCAL fResult, lnFail
      IF EMPTY(m.lcRemoteFile)
         This.SetExtendedError(_FTPS_UE_FNDEF,"lcRemoteFile")
         RETURN .F.
      ENDIF
      IF EMPTY(m.lcLocalFile)
         This.SetExtendedError(_FTPS_UE_FNDEF,"lcLocalFile")
         RETURN .F.
      ENDIF
      lnFlag=IIF(PCOUNT()<4,FTP_TRANSFER_TYPE_UNKNOWN,m.lnFlag)

      IF This.OpenFTPConnection(This.cCurrentDir)     && Open an FTP Handle
         lnFail=IIF(m.llFailIfExists,1,0)
                    
         lcLocalFile = m.lcLocalFile + cNULL
         lcRemoteFile = m.lcRemoteFile + cNULL
                
         =This.BeforeGetFTPFile(@m.lcRemoteFile, @m.lcLocalFile, m.llFailIfExists,m.lnFlag)
         fResult = FtpGetFile(This.nConnect_Handle, @m.lcRemoteFile, @m.lcLocalFile, m.lnFail, ;
                              FILE_ATTRIBUTE_NORMAL, BITOR(This.nCachingType,m.lnFlag), 0)
         =This.GetExtendedError()
         =This.AfterGetFTPFile(@m.lcRemoteFile, @m.lcLocalFile, m.llFailIfExists,m.lnFlag,m.fResult)
                    
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
                    
         RETURN m.fResult = 1
      ENDIF
      RETURN .F.