Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 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.

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Port = 21

//  Connect without logging in.
li_Success = loo_Ftp.ConnectOnly()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Connected (not yet logged in)."

//  The greeting is now available; credentials can be set based on it, then authenticate.
loo_Ftp.Username = "myFtpLogin"
loo_Ftp.Password = "myPassword"

li_Success = loo_Ftp.LoginAfterConnectOnly()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Logged in."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp