Class FtpFileSystem


public class FtpFileSystem extends FileSystem
Class for accessing the FTP file system.
  • Constructor Details

    • FtpFileSystem

      public FtpFileSystem()
      Connects to the FTP server on localhost (port 21) as an anonymous user.
    • FtpFileSystem

      public FtpFileSystem(String hostName, int port)
      Connects to the specified FTP server with credentials supplied through a CredentialsResolver (see setCredentialsResolver(CredentialsResolver)).
      Parameters:
      hostName - hostname of the FTP server
      port - the port to connect to
    • FtpFileSystem

      public FtpFileSystem(String hostName, int port, String userName, String password)
      Connects to the specified FTP server.
      Parameters:
      hostName - hostname of the FTP server
      port - the port to connect to
      userName - name of the user
      password - password of the user
  • Method Details

    • setCredentialsResolver

      public FtpFileSystem setCredentialsResolver(CredentialsResolver credentialsResolver)
      Sets the resolver supplying this file system's user name and password (Credentials.USERNAME/Credentials.PASSWORD) — resolved on each open(), never at construction, so rotated secrets are picked up on the next connection. Keys absent from the resolved credentials fall back to the constructor-supplied values.
      Overrides:
      setCredentialsResolver in class FileSystem
    • open

      public void open() throws DataException
      Opens a connection to an FTP server.
      Overrides:
      open in class Endpoint
      Throws:
      DataException
    • close

      public void close() throws DataException
      Closes the connection from an FTP server.
      Overrides:
      close in class FileSystem
      Throws:
      DataException
    • readFile

      public InputStream readFile(String folderName, String fileName) throws Throwable
      Reads a file in the specified folder. To specify a nested folder use "/" as separator.
      Example:
      • readFile("folderOne", "fileName") - reads the file in folderOne which is under the root folder
      • readFile("folderOne/folderTwo", "fileName") - reads the file in folderTwo which is under folderOne
      • readFile("/folderOne/folderTwo", "fileName") - reads the file in folderTwo which is under folderOne
      Returns:
      an InputStream or null
      Throws:
      Throwable
    • readFile

      public InputStream readFile(String fileName) throws Throwable
      Reads the specified file in the root folder.
      Returns:
      an InputStream or null
      Throws:
      Throwable
    • listFolder

      public List<FTPFile> listFolder(String folderName) throws Throwable
      Returns the contents of the folder. To specify a nested folder use "/" as separator.
      Example:
      • listFolder("folderOne") - reads the contents of folderOne which is under the root folder
      • listFolder("folderOne/folderTwo") - reads the contents of folderTwo which is under folderOne
      • listFolder("/folderOne/folderTwo") - reads the contents of folderTwo which is under folderOne
      Throws:
      Throwable
    • listRootFolder

      public List<FTPFile> listRootFolder() throws Throwable
      Returns the contents of the root folder.
      Throws:
      Throwable
    • writeFile

      public OutputStream writeFile(String fileName) throws Throwable
      Writes a file to the root folder. If there is a file with the same name, it is overwritten.
      Parameters:
      fileName - the name of the file
      Throws:
      Throwable
    • writeFile

      public OutputStream writeFile(String folderName, String fileName) throws Throwable
      Writes a file to the specified folder. If there is a file with the same name, it is overwritten.
      Parameters:
      folderName - the folder name
      fileName - the name of the file
      Throws:
      Throwable
    • getDataConnectionMode

      public DataConnectionMode getDataConnectionMode()
      Returns the data connection mode applied at open() (defaults to DataConnectionMode.ACTIVE_LOCAL).
    • setDataConnectionMode

      public FtpFileSystem setDataConnectionMode(DataConnectionMode dataConnectionMode)
    • getFileTransferType

      public FileTransferType getFileTransferType()
      Returns the file transfer type applied at open() (defaults to FileTransferType.BINARY).
    • setFileTransferType

      public FtpFileSystem setFileTransferType(FileTransferType fileTransferType)
    • getFileTransferMode

      public FileTransferMode getFileTransferMode()
      Returns the file transfer mode applied at open() (defaults to FileTransferMode.STREAM).
    • setFileTransferMode

      public FtpFileSystem setFileTransferMode(FileTransferMode fileTransferMode)
      Parameters:
      fileTransferMode -
    • isRemoteVerification

      public boolean isRemoteVerification()
      Indicates if data connections must be with the same host as the control connection, applied at open() (defaults to true).
    • setRemoteVerification

      public FtpFileSystem setRemoteVerification(boolean remoteVerification)
      Indicates if data connections must be with the same host as the control connection, applied at open() (defaults to true).