amoebacode

FTPClient Usage

This small test class demonstrates basic FTPClient usage.

import com.amoebacode.ftp.FTPClient;
import java.io.IOException;

public class FTPTest {

  public static void main(String[] args) {
    runTest();
  }

  private static void runTest() {
    FTPClient ftpClient = new FTPClient(true);
    try {
      ftpClient.openConnection("ftp.redhat.com");
      ftpClient.loginAnonymous();
      System.out.println("System type: " + ftpClient.getSystemType());
      ftpClient.changeDirectory("/pub/redhat/linux/7.3/en/doc");
      System.out.println("Current directory: " + ftpClient.getCurrentDirectory());
      System.out.println("File list: " + ftpClient.getNameList());
      System.out.println("Modification time: " + ftpClient.getModificationTime("index-en.html"));
      System.out.println("File size: " + ftpClient.getFileSize("index-en.html"));
      ftpClient.downloadFile("index-en.html", "index-en.html", true);
      ftpClient.downloadDirectory("RedHat", "RedHat", false, true);
      ftpClient.parentDirectory();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        ftpClient.closeConnection();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

}