Search code examples
javaftpapache-commons-net

How do I create a robust FTP connection using commons-net


We've had a lots of issues where our ftp connection hangs indefinitely, causing the program to hang.

How do I configure FTPClient to not do this?


Solution

  • Here's what I'm thinking so far.

    FTPClient ftpClient = new FTPClient();
    ftpClient.setDataTimeout(timeout);
    ftpClient.setConnectTimeout(timeout); // otherwise the connect call might hang
    ftpClient.connect(this.serverAddr);