Class FtpClient

java.lang.Object
org.h2.dev.ftp.FtpClient

public class FtpClient extends Object
A simple standalone FTP client.
  • Method Details

    • open

      public static FtpClient open(String url) throws IOException
      Open an FTP connection.
      Parameters:
      url - the FTP URL
      Returns:
      the ftp client object
      Throws:
      IOException
    • login

      public void login(String userName, String password) throws IOException
      Login to this FTP server (USER, PASS, SYST, SITE, STRU F, TYPE I).
      Parameters:
      userName - the user name
      password - the password
      Throws:
      IOException
    • close

      public void close() throws IOException
      Close the connection (QUIT).
      Throws:
      IOException
    • changeWorkingDirectory

      public void changeWorkingDirectory(String dir) throws IOException
      Change the working directory (CWD).
      Parameters:
      dir - the new directory
      Throws:
      IOException
    • changeDirectoryUp

      public void changeDirectoryUp() throws IOException
      Change to the parent directory (CDUP).
      Throws:
      IOException
    • makeDirectory

      public void makeDirectory(String dir) throws IOException
      Create a directory (MKD).
      Parameters:
      dir - the directory to create
      Throws:
      IOException
    • retrieve

      public byte[] retrieve(String fileName) throws IOException
      Read a file.
      Parameters:
      fileName - the file name
      Returns:
      the content, null if the file doesn't exist
      Throws:
      IOException
    • removeDirectory

      public void removeDirectory(String dir) throws IOException
      Remove a directory (RMD).
      Parameters:
      dir - the directory to remove
      Throws:
      IOException
    • removeDirectoryRecursive

      public void removeDirectoryRecursive(String dir) throws IOException
      Remove all files and directory in a directory, and then delete the directory itself.
      Parameters:
      dir - the directory to remove
      Throws:
      IOException
    • store

      public void store(String fileName, InputStream in) throws IOException
      Store a file (STOR).
      Parameters:
      fileName - the file name
      in - the input stream
      Throws:
      IOException
    • storeRecursive

      public void storeRecursive(File file) throws IOException
      Copy a local file or directory to the FTP server, recursively.
      Parameters:
      file - the file to copy
      Throws:
      IOException
    • nameList

      public String nameList(String dir) throws IOException
      Get the directory listing (NLST).
      Parameters:
      dir - the directory
      Returns:
      the listing
      Throws:
      IOException
    • list

      public String list(String dir) throws IOException
      Get the directory listing (LIST).
      Parameters:
      dir - the directory
      Returns:
      the listing
      Throws:
      IOException
    • exists

      public boolean exists(String dir, String name) throws IOException
      Check if a file exists on the FTP server.
      Parameters:
      dir - the directory
      name - the directory or file name
      Returns:
      true if it exists
      Throws:
      IOException
    • listFiles

      public File[] listFiles(String dir) throws IOException
      List the files on the FTP server.
      Parameters:
      dir - the directory
      Returns:
      the list of files
      Throws:
      IOException