Sample code for 30+ languages & platforms
PureBasic

Connect Through a Traditional FTP Proxy

See more FTP Examples

Demonstrates connecting through a traditional FTP application proxy or firewall using ProxyHostname, ProxyPort, ProxyUsername, ProxyPassword, and ProxyMethod.

Background: A traditional FTP proxy speaks FTP and relays your login to the real server using one of several site-specific handshake sequences — which is why ProxyMethod exists: it selects the exact USER/PASS/SITE order the proxy expects (0 means no FTP proxy). The proxy's own credentials are separate from the FTP server login. Choose the ProxyMethod value that matches your firewall's documented behavior.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkFtp2.pb"

Procedure ChilkatExample()

    success.i = 0

    ftp.i = CkFtp2::ckCreate()
    If ftp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkFtp2::setCkHostname(ftp, "ftp.example.com")
    CkFtp2::setCkUsername(ftp, "myFtpLogin")

    ;  The FTP proxy/firewall to connect through.
    CkFtp2::setCkProxyHostname(ftp, "ftp-proxy.example.com")
    CkFtp2::setCkProxyPort(ftp, 21)

    ;  The proxy's own credentials (distinct from the FTP server login).
    CkFtp2::setCkProxyUsername(ftp, "myProxyLogin")
    CkFtp2::setCkProxyPassword(ftp, "myProxyPassword")

    ;  ProxyMethod selects the login sequence the proxy expects.  0 (default) means no FTP proxy;
    ;  values 1 and up select specific USER/PASS/SITE sequences documented for the property.
    CkFtp2::setCkProxyMethod(ftp, 1)

    ;  Normally you would not hard-code the password in source.  You should instead obtain it
    ;  from an interactive prompt, environment variable, or a secrets vault.
    CkFtp2::setCkPassword(ftp, "myPassword")

    success = CkFtp2::ckConnect(ftp)
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        ProcedureReturn
    EndIf

    Debug "Connected through the FTP proxy."

    success = CkFtp2::ckDisconnect(ftp)
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        ProcedureReturn
    EndIf



    CkFtp2::ckDispose(ftp)


    ProcedureReturn
EndProcedure