Visual FoxPro
Visual FoxPro
Connect to an FTP Server Without Logging In
See more FTP Examples
Demonstrates the Chilkat Ftp2.ConnectOnly method, which establishes the connection (including any proxy and TLS setup) and receives the greeting, but does not send USER or PASS. It takes no arguments; authentication is completed with LoginAfterConnectOnly.
Background: Splitting connect from login gives you a window between the two — to read the greeting, decide which account to use, or set up TLS options that depend on the server — that the all-in-one
Connect does not. After ConnectOnly the control connection is open and CheckConnection returns true even though the session is not yet authenticated.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loFtp
lnSuccess = 0
* Demonstrates the Ftp2.ConnectOnly method, which establishes the connection (including any proxy
* and TLS setup) and receives the greeting, but does NOT send USER or PASS. It takes no
* arguments. Authentication is completed separately with LoginAfterConnectOnly.
loFtp = CreateObject('Chilkat.Ftp2')
loFtp.Hostname = "ftp.example.com"
loFtp.Port = 21
* Connect without logging in.
lnSuccess = loFtp.ConnectOnly()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
? "Connected (not yet logged in)."
* The greeting is now available; credentials can be set based on it, then authenticate.
loFtp.Username = "myFtpLogin"
loFtp.Password = "myPassword"
lnSuccess = loFtp.LoginAfterConnectOnly()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
? "Logged in."
lnSuccess = loFtp.Disconnect()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
RELEASE loFtp