OpenInternet Method
Class: FTP_SERVICE
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.
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
Direction Input
Optional  
Can be one of the following:
ValueDescription
INTERNET_FLAG_ASYNC Only asynchronous requests.
INTERNET_FLAG_FROM_CACHE All entities are returned from the cache.
INTERNET_FLAG_OFFLINE All entities are returned from the cache.
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
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 OpenInternet Source Code
LPARAMETERS INP lcUserName, INP lcPassword,INP lcIPAddress, INP lcPort, OPT_INP  lnFlag
      LOCAL lnPCount, fResult,lnConnectHandle,liAccessType,lcProxyBypass,lcProxyName

      * Check Passed Parameters
      lnPCount = PCOUNT()

      IF lnPCount < 4
         This.nResult_Code = ERROR_INTERNET_BAD_OPTION_LENGTH
         RETURN .F.
      ENDIF
      lnFlag=IIF(lnPCount<5,0,lnFlag)

      * Make sure parameters are of the correct type
      IF (TYPE("lcUserName") != "C") OR ;
         (TYPE("lcPassword") != "C") OR ;
         (TYPE("lcIPAddress") != "C") OR ;
         (TYPE("lcPort") != "C")
         This.nResult_Code = ERROR_INVALID_PARAMETER
         RETURN .F.
      ENDIF

      * Check Parameter Values
      IF EMPTY(lcUserName) OR EMPTY(lcPassword) OR EMPTY(lcIPAddress)
         This.nResult_Code = ERROR_INTERNET_BAD_OPTION_LENGTH            
         RETURN .F.
      ENDIF

      IF This.LoadAPIFuncs() != ERROR_SUCCESS
         RETURN .F.
      ENDIF


      * Open Handle to Internet
      * Set Parameters
      This.cUserName = lcUserName + cNULL           && Store FTP Connection information
      This.cPassword = lcPassword + cNULL
      This.cIPAddress = lcIPAddress + cNULL
      This.cPort = lcPort


      IF EMPTY(This.cProxyHost) OR ISNULL(This.cProxyHost)
         lcProxyName = .NULL.
         liAccessType=INTERNET_OPEN_TYPE_DIRECT
         This.lUseProxy = .F.
         lcProxyBypass=.NULL.
      ELSE

         *protocol=proxyhost:proxyport
         *ftp=ftp://ftp_proxy_name:21 
         lcProxyName = This.cProxyProtocol+"="+ This.cProxyHost + ":" + ALLTRIM(This.cProxyport) + cNULL
         liAccessType=INTERNET_OPEN_TYPE_PROXY
         This.lUseProxy = .T.
         lcProxyBypass=This.cIPAddress
      ENDIF

      This.nInet_Handle = InternetOpen((This.cAgent), INTERNET_OPEN_TYPE_DIRECT, @lcProxyName, @lcProxyBypass,lnFlag)
      This.GetExtendedError()


      * Unable to Get a Connection into the Internet
      IF This.nInet_Handle = 0
         This.CloseFTPConnection()
         RETURN .F.
      ENDIF


      * 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
      RETURN fResult