Sample code for 30+ languages & platforms
Rust

Set FTP Connection and Read Timeouts

See more FTP Examples

Demonstrates the timeout properties ConnectTimeout, ReadTimeout, and IdleTimeoutMs.

Background: The three timeouts guard different phases: ConnectTimeout (in seconds) bounds how long a connection attempt blocks so an unreachable server fails promptly; ReadTimeout (seconds) limits how long a data connection may stall without new data; and IdleTimeoutMs (milliseconds) caps a lack of forward progress overall. Tuning them prevents a hung server or flaky link from freezing an automated job indefinitely.

Chilkat Rust Downloads

Rust

let ftp = chilkat::Ftp2::new();

ftp.set_hostname("ftp.example.com");
ftp.set_username("myFtpLogin");

// Maximum seconds to wait for the TCP connection to be accepted.
ftp.set_connect_timeout(15);

// Maximum seconds a data connection may go without receiving more data before timing out.
ftp.set_read_timeout(30);

// Maximum milliseconds without a control-channel response or forward progress before failing.
ftp.set_idle_timeout_ms(20000);

// 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.set_password("myPassword");

if ftp.connect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}

println!("Connected with custom timeouts.");

if ftp.disconnect().is_err() {
    println!("{}", ftp.last_error_text());
    return;
}