OpenInternet Method
Class: FTP_SERVICE
Description:Attempts to open a connection to the FTP server
Attempts to open a connection to the FTP server.
Note
Port 21 is the default FTP port used on FTP servers.
=
Object.OpenInternet
Parameter
lcUserName
User name
Type Character
Direction Input
A valid user id on the FTP server.
lcPassword
Password
Type Character
Direction Input
A valid password for the UserName. Can be empty.
lcIPAddress
FTP server IP/DNS name
Type Character
Direction Input
The Site Alias or IP number of the FTP Server.
lcPort
Port of FTP server
Type Character
Direction Input
Optional  
The number of the Port on the Server to connect to.
lnFlag
The flags that indicate various options.
Type Numeric/Array
By reference  
Direction Input
Optional  
The value can be single number value of array number values. If You use single value, then passed value is equal to dwFlags parameter of API function. This can be a combination of these values:
ValueDescription
INTERNET_FLAG_ASYNCOnly asynchronous requests.
INTERNET_FLAG_FROM_CACHEAll entities are returned from the cache.
INTERNET_FLAG_OFFLINEAll entities are returned from the cache.

If you use array of numbers, then first value (_FTPS_FA_Default) is equal to dwFlags parameter of API function. Second value (_FTPS_FA_AccessType) is equal to dwAccessType parameter of API funtion. This can be a combination of these values:

ValueDescription
INTERNET_OPEN_TYPE_DIRECTResolves all host names locally.
INTERNET_OPEN_TYPE_PRECONFIGRetrieves the proxy or direct configuration from the registry.
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXYRetrieves the proxy or direct configuration from the registry and prevents the use of a startup Microsoft JScript® or Internet Setup (INS) file.
The value is ignore then you use proxy mode.

Assumed from MSDN.

Return value Boolean
.T. if the function succeded in making a connection to the internet and the FTP server. Returns .F. if the function was unable to connect to the internet or the FTP server.
Example

Using single value

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

Using array value

#INCLUDE "ftp.h" LOCAL loFTP LOCAL ARRAY laFlags(_FTPS_FA_MaxSize) laFlags(_FTPS_FA_Default)=0 laFlags(_FTPS_FA_AccessType)=INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY SET PROCEDURE TO ftp.prg ADDITIVE loFTP=CREATEOBJECT('ftp_service') IF loFTP.OpenInternet("ABONNE", "PWD", "10.10.10.10", "21",@laFlags) 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 OpenInternet Source Code
      LPARAMETERS INP lcUserName, INP lcPassword,INP lcIPAddress, INP lcPort, OPT_INP  lnFlag
      LOCAL lnPCount, fResult,lnConnectHandle,liAccessType,lcProxyBypass,lcProxyName

      * olrrai added:
      This.FTPOpen = .F.
           
      * Check Passed Parameters
      lnPCount = PCOUNT()
                      
      IF m.lnPCount < 4
         This.nResult_Code = ERROR_INTERNET_BAD_OPTION_LENGTH
         RETURN .F.
      ENDIF
      lnFlag=IIF(m.lnPCount<5,0,m.lnFlag)
               
      * Make sure parameters are of the correct type
      IF (TYPE("m.lcUserName") != "C") OR ;
         (TYPE("m.lcPassword") != "C") OR ;
         (TYPE("m.lcIPAddress") != "C") OR ;
         (TYPE("m.lcPort") != "C")
         This.nResult_Code = ERROR_INVALID_PARAMETER
         RETURN .F.
      ENDIF
               
      * Check Parameter Values
      IF EMPTY(m.lcUserName) OR EMPTY(m.lcPassword) OR EMPTY(m.lcIPAddress)
         This.nResult_Code = ERROR_INVALID_PARAMETER
         RETURN .F.
      ENDIF
               
      IF This.LoadAPIFuncs() != ERROR_SUCCESS
         RETURN .F.
      ENDIF
               
               
      * Open Handle to Internet
      * Set Parameters
      This.cUserName = m.lcUserName + cNULL           && Store FTP Connection information
      This.cPassword = m.lcPassword + cNULL
      This.cIPAddress = m.lcIPAddress + cNULL
      This.cPort = m.lcPort


      IF EMPTY(This.cProxyHost) OR ISNULL(This.cProxyHost)
         lcProxyName = .NULL.
         lcProxyBypass=.NULL.
         liAccessType=IIF(TYPE("m.lnFlag("+LTRIM(STR(_FTPS_FA_AccessType,11))+")")="N",m.lnFlag(_FTPS_FA_AccessType),INTERNET_OPEN_TYPE_DIRECT)
         This.lUseProxy = .F.
      ELSE
         *protocol=proxyhost:proxyport
         *ftp=ftp://ftp_proxy_name:21 
         lcProxyName = This.cProxyProtocol+"="+ This.cProxyHost + ":" + ALLTRIM(This.cProxyport) + cNULL
         lcProxyBypass=This.cIPAddress
         liAccessType=INTERNET_OPEN_TYPE_PROXY
         This.lUseProxy = .T.
      ENDIF
                                                      
      This.nInet_Handle = InternetOpen((This.cAgent), m.liAccessType, @m.lcProxyName, @m.lcProxyBypass,m.lnFlag)
      This.GetExtendedError()
               
               
      * Unable to Get a Connection into the Internet
      IF This.nInet_Handle = 0
         This.CloseFTPConnection()
         RETURN .F.
      ENDIF

      *- Set options
      This.WinInetSetOptions() && olrrai fix
           
    
      * This Opens the FTP site and Gets the Current Directory.  The handle to the FTP site is opened
      * and closed for each call to any function.    
      * Open FTP Site 
      fResult=This.OpenFTPConnection(This.cStartupFolder)
      =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
      This.FTPOpen = m.fResult && olrrai added
      RETURN m.fResult