Attempts to open a connection to the FTP server.
Note
Port 21 is the default FTP port used on FTP servers.
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 |
The number of the Port on the Server to connect to.
.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.
Source Code
LPARAMETERS lcUserName, lcPassword, lcIPAddress, lcPort
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
* 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, 0)
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