ReadFTPFile Method
Class: FTP_SERVICE
=
Object.ReadFTPFile
Parameter
lcRemoteFile
Remote file name
Type Character
Direction Input
Name and Path of the file on the FTP Server to bring down.
lcData
Local file name or string buffer
Type Character
By reference  
Direction Input/Output
liData
Buffer size
Type Integer
Direction Input
liRStart
Start position of remote file
Type Integer
Direction Input
If value 0 , then file will be read all. If value >0 , then file will be read from position.
liLStart
Start position of local file/string buffer
Type Integer
Direction Input
If value 0 , then data will write into begin of file. If value >0 , then file will be write from into start position.
liFlags
Mode flags
Type Boolean
Direction Input
List of types
ValueDescription
_FTPS_RWF_Resume Resume mode
_FTPS_RWF_File lcData is file name.
_FTPS_RWF_String lcData is string.
_FTPS_RWF_Rewrite Rewrite mode
Return value Boolean
The return value is .T. if file is downloaded or .F. is not.



See also
Expand/Collapse source code of procedure ReadFTPFile Source Code
      LPARAMETERS lcRemoteFile, lcData,liData,liRStart,liLStart,liFlags
      LOCAL fResult,lihFTP,lcBuffer,liData,liRead,lihFile,llFast,lcAll,llAppend,liFSize
      lihFile=0
      liData=IIF(PCOUNT()<3,512,liData)
      liData=IIF(liData<=0,512,liData)

      liRStart=IIF(PCOUNT()<4,0,liRStart)
      liLStart=IIF(PCOUNT()<5,0,liLStart)
      liFlags=IIF(PCOUNT()<6,_FTPS_RWF_Resume+_FTPS_RWF_File,liFlags)

      IF !BITTEST(liFlags,0) && File?
         llFast=VAL(STRTRAN(SUBS(VERSION(),LEN("Visual FoxPro ")+1,2),"0",""))>6
         IF !llFast
            lihFile=FOPEN(lcData,0)
            lihFile=IIF(lihFile<=0,FCREATE(lcData,0),lihFile)

            IF lihFile<=0
               RETURN .F.
            ENDIF
            =IIF(BITTEST(liFlags,1),; && rewrite, skip to new position
                 FSEEK(lihFile,liLStart,0),;
                 FSEEK(lihFile,liRStart,0)) && resume native mode
         ELSE
            lcAll=FILETOSTR(lcData)
            lcAll=IIF(BITTEST(liFlags,1),; && rewrite, skip to new position
                      LEFT(lcAll,liLStart),LEFT(lcAll,liRStart))
         ENDIF
      ELSE
         lcData=IIF(TYPE("lcData")#"C","",lcdata)
         lcData=IIF(BITTEST(liFlags,1),; && rewrite, skip to new position
                    LEFT(lcData,liLStart),LEFT(lcData,liRStart))
         llFast=.T.
      ENDIF

      IF This.OpenFTPConnection(This.cStartupFolder) && Open an FTP Handle
         lcRemoteFile = lcRemoteFile + cNULL

         =This.BeforeReadFTPFile(@lcRemoteFile, @lcData,liData,liRStart,liLStart,liFlags)
         IF liRStart<=0 && All data
            STORE FtpOpenFile(This.nConnect_Handle, @lcRemoteFile, GENERIC_READ, ;
                              FTP_TRANSFER_TYPE_BINARY, 0) TO fResult,lihFTP
            =This.GetExtendedError()
         ELSE
            fResult=0
            =This.FTPCommand("REST "+LTRIM(STR(liRStart,11)), FTP_TRANSFER_TYPE_BINARY,0,.NULL.)
            IF This.FTPCommand("RETR "+lcRemoteFile, FTP_TRANSFER_TYPE_BINARY,0,@lihFTP)
               fResult=1
            ENDIF
         ENDIF

         IF fResult #0 && OK, FTP file is openned
            lii=0
            STORE 1 TO fResult,liRead

            DO WHILE liRead>0
               liRead=0
               lcBuffer=SPACE(liData)
               fResult = InternetReadFile(lihFTP, @lcBuffer, liData, @liRead)
               =This.GetExtendedError()
               =This.AtReadFTPFile(@lcRemoteFile, @lcData,liData,liRStart,liLStart,liFlags,@lcBuffer,fResult)

               IF !BITTEST(liFlags,0) && File?
                  IF llFast AND liRead>0
                     IF LEN(lcAll)+liRead>_FTPS_MaxFileSize
                        =STRTOFILE(lcAll,lcData,llAppend)
                        llAppend=.T.
                        lcAll=""
                     ENDIF
                     lcAll=lcAll+LEFT(lcBuffer,liRead)
                  ELSE
                     IF liRead>0
                        =FWRITE(lihFile,LEFT(lcBuffer,liRead),liRead)
                     ENDIF
                  ENDIF
               ELSE
                  lcData=lcData+LEFT(lcBuffer,liRead)
               ENDIF
               lii=lii+liRead
            ENDDO

            IF !BITTEST(liFlags,0)
                =IIF(llFast AND LEN(lcAll)>0,; && File?
                     STRTOFILE(lcAll,lcData,llAppend),.T.)
                =IIF(lihFile>0 AND !llFast,FCLOSE(lihFile),.T.)
            ENDIF
            =InternetCloseHandle(lihFTP)

            =IIF(liRStart>0,This.FTPCommand("NOOP", FTP_TRANSFER_TYPE_BINARY,0,.NULL.),.T.)
         ENDIF

         =This.AfterReadFTPFile(@lcRemoteFile, @lcData,liData,liRStart,liLStart,liFlags,fResult)
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN  fResult = 1
      ENDIF
      RETURN .F.