Java
Java
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 Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkFtp2 ftp = new CkFtp2();
ftp.put_Hostname("ftp.example.com");
ftp.put_Username("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.
ftp.put_SoRcvBuf(4194304);
ftp.put_SoSndBuf(524288);
// PreferIpv6 (default false) chooses IPv6 over IPv4 when a hostname resolves to both.
ftp.put_PreferIpv6(false);
// ClientIpAddress is normally left unset; set it on a multihomed host to bind the outgoing
// connection to a specific local interface.
ftp.put_ClientIpAddress("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.
ftp.put_Password("myPassword");
success = ftp.Connect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
System.out.println("Connected with custom socket options.");
success = ftp.Disconnect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
}
}