Sample code for 30+ languages & platforms
PureBasic

FTP Socket Buffer and Address Options

See more FTP Examples

Demonstrates the SoRcvBuf, SoSndBuf, PreferIpv6, and ClientIpAddress properties.

Background: These are low-level knobs for specific situations. Larger send/receive buffers can improve throughput on high-bandwidth, high-latency links, though the defaults suit the common case. PreferIpv6 only matters when a hostname resolves to both address families, choosing which to try first. ClientIpAddress is normally left unset; set it on a multihomed host to bind the outgoing connection to a particular local interface. Change any of these only with a concrete reason.

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")

    ;  SoRcvBuf and SoSndBuf set the TCP socket receive/send buffer sizes.  The defaults are tuned for
    ;  the common case; larger values can sometimes help throughput on high-latency links.
    CkFtp2::setCkSoRcvBuf(ftp, 4194304)
    CkFtp2::setCkSoSndBuf(ftp, 524288)

    ;  PreferIpv6 (default 0) chooses IPv6 over IPv4 when a hostname resolves to both.
    CkFtp2::setCkPreferIpv6(ftp, 0)

    ;  ClientIpAddress is normally left unset; set it on a multihomed host to bind the outgoing
    ;  connection to a specific local interface.
    CkFtp2::setCkClientIpAddress(ftp, "192.168.1.50")

    ;  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 with custom socket options."

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



    CkFtp2::ckDispose(ftp)


    ProcedureReturn
EndProcedure