Sample code for 30+ languages & platforms
PowerBuilder

Log In After ConnectOnly on an FTP Server

See more FTP Examples

Demonstrates the Chilkat Ftp2.LoginAfterConnectOnly method, which authenticates a control connection previously established by ConnectOnly. It takes no arguments, sends USER, PASS, and ACCT when required, then performs normal post-login initialization.

Background: This is the second half of the two-step connect. Beyond sending the credentials, it runs the same post-login setup Connect would — for example issuing TYPE I and any auto-negotiated features — so the session ends up in the same ready state either way. The value of the split is entirely in what you can do in the gap between the two calls.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  Demonstrates the Ftp2.LoginAfterConnectOnly method, which authenticates a control connection
//  previously established by ConnectOnly.  It takes no arguments and sends USER, PASS, and (when
//  required) ACCT, then performs normal post-login initialization.

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

//  First 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

//  Set credentials (for example, after inspecting the greeting), then log in.
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