Class FtpSession

java.lang.Object
com.nt.udc.ndk.util.FtpSession
All Implemented Interfaces:
FtpSupportIntf

public class FtpSession extends Object implements FtpSupportIntf
Handles some common methods and variables that are used in a single Ftp session.
  • Constructor Details

    • FtpSession

      public FtpSession(LoggerIfc l)
      Creats an FtpSession object.
      Parameters:
      logger - event logger
    • FtpSession

      public FtpSession(String host, String login, String password, LoggerIfc l)
      Creates an FtpSession object with the given host, login and password.
      Parameters:
      host - remote host (ip or hostname)
      login - login name
      password - login password
      logger - event logger
    • FtpSession

      public FtpSession(String host, String login, String password, LoggerIfc l, int timerDelay)
    • FtpSession

      public FtpSession(String host, int port, String login, String password, LoggerIfc l)
      Creates an FtpSession object with the given host, login and password.
      Parameters:
      host - remote host (ip or hostname)
      port - Ftp port number, default is 21
      login - login name
      password - login password
      logger - event logger
    • FtpSession

      public FtpSession(String host, int port, String login, String password, LoggerIfc l, int timerDelay)
      Creates an FtpSession object with the given host, login and password and timer delay..
      Parameters:
      host - remote host (ip or hostname)
      port - Ftp port number, default is 21
      login - login name
      password - login password
      l - logger interface of the node
      timerDelay - the timeout value for ftp connection,transfer.
  • Method Details

    • setHost

      public void setHost(String host)
      Sets the remote host.
      Parameters:
      host - remote host, as an ip address or name
    • setPort

      public void setPort(int port)
    • setLogin

      public void setLogin(String login)
      Sets the login name.
      Parameters:
      login - login name
    • setPassword

      public void setPassword(String pw)
      Sets the login password
      Parameters:
      pw - login password
    • setBinaryFileType

      public void setBinaryFileType()
      Sets the transfer file type to BINARY
      Specified by:
      setBinaryFileType in interface FtpSupportIntf
    • setAsciiFileType

      public void setAsciiFileType()
      Sets the transfer file type to ASCII
      Specified by:
      setAsciiFileType in interface FtpSupportIntf
    • enableLocalActiveMode

      public void enableLocalActiveMode()
      Enables local active mode for transfers
    • enableLocalPassiveMode

      public void enableLocalPassiveMode()
      Enables local passive mode for transfers
    • setTimeout

      public void setTimeout(int timeout)
      Sets the timeout for FTP operations
      Parameters:
      timeout - - timeout interval in milliseconds
    • getHost

      public String getHost()
      Returns the remote host
      Specified by:
      getHost in interface FtpSupportIntf
      Returns:
      remote host name
    • getPort

      public int getPort()
    • getLogin

      public String getLogin()
      Returns the login name
      Specified by:
      getLogin in interface FtpSupportIntf
      Returns:
      login name
    • getTimeout

      public long getTimeout()
      Returns the timeout for FTP operations
      Returns:
      timeout interval in milliseconds
    • getPassword

      public String getPassword()
      Returns the login password
      Specified by:
      getPassword in interface FtpSupportIntf
      Returns:
      login password
    • login

      public boolean login() throws IOException
      Logs into the remote host, using the internally set ip address, login name and password.

      Returns:
      true, if login is successful. false, otherwise.
      Throws:
      IOException
    • login

      public boolean login(String ip, String login, String password) throws IOException
      Logs into the remote host, using the given ip address, login name and password.

      Specified by:
      login in interface FtpSupportIntf
      Parameters:
      ip - remote ip address
      login - login name
      password - login password

      Returns:
      true, if login is successful. false, otherwise.
      Throws:
      IOException
    • logout

      public boolean logout() throws IOException
      Logs out from the remote server
      Specified by:
      logout in interface FtpSupportIntf
      Throws:
      IOException
    • disconnect

      public void disconnect() throws IOException
      Disconnects from the remote server
      Specified by:
      disconnect in interface FtpSupportIntf
      Throws:
      IOException
    • get

      public boolean get(String localFile, String remoteFile) throws IOException
      Copy the remote file to the local file. One must set the appropriate file type before the get; the default is binary mode.

      Specified by:
      get in interface FtpSupportIntf
      Parameters:
      localFile - Local file name.
      remoteFile - Remote file name.

      Returns:
      true, if get was successful.
      Throws:
      IOException
    • put

      public boolean put(String localFile, String remoteFile) throws IOException
      Copy the local file to the remote file. One must set the appropriate file type before the get; the default is binary mode.

      Specified by:
      put in interface FtpSupportIntf
      Parameters:
      localFile - Local file name.
      remoteFile - Remote file name.

      Returns:
      true, if get was successful.
      Throws:
      IOException
    • delete

      public boolean delete(String fileName) throws IOException
      Remove a file from the remote host.
      Specified by:
      delete in interface FtpSupportIntf
      Parameters:
      fileName - remote file pathname
      Returns:
      true, if delete was successful
      Throws:
      IOException
    • pwd

      public String pwd() throws IOException
      Returns the present working directory.
      Specified by:
      pwd in interface FtpSupportIntf
      Returns:
      present working directory
      Throws:
      IOException
    • cd

      public boolean cd(String remotePath) throws IOException
      Changes the current working directory.
      Specified by:
      cd in interface FtpSupportIntf
      Parameters:
      remotePath - new remote directory
      Returns:
      present working directory
      Throws:
      IOException
    • listFiles

      public String[] listFiles(String remotePath) throws IOException
      Returns the list of files in the given remote directory.
      Specified by:
      listFiles in interface FtpSupportIntf
      Parameters:
      remotePath - remote directory to list
      Returns:
      list of files (null if no files found)
      Throws:
      IOException
    • listFiles

      public String[] listFiles() throws IOException
      Returns the list of files in the current remote directory.
      Specified by:
      listFiles in interface FtpSupportIntf
      Returns:
      list of files (null if no files found)
      Throws:
      IOException
    • listItems

      public FtpItem[] listItems(String remotePath) throws IOException
      Returns the list of files in the given remote directory.
      Parameters:
      remotePath - remote directory to list
      Returns:
      list of files (null if no files found)
      Throws:
      IOException
    • listItems

      public FtpItem[] listItems() throws IOException
      Returns the list of files in the current remote directory.
      Returns:
      list of files (null if no files found)
      Throws:
      IOException
    • listDirectories

      public String[] listDirectories() throws IOException
      lists the directories in the current working directory
      Returns:
      array of the directory names
      Throws:
      IOException
    • listDirectories

      public String[] listDirectories(String remotePath) throws IOException
      lists the directories of the remote path
      Specified by:
      listDirectories in interface FtpSupportIntf
      Parameters:
      remotePath - remote directory to list
      Returns:
      array of the directory names
      Throws:
      IOException
    • getTimestamp

      public Date getTimestamp(String remoteFile) throws IOException
      gets the timestamp of the remote file
      Specified by:
      getTimestamp in interface FtpSupportIntf
      Parameters:
      remoteFile - remote path for which to get timestamp
      Returns:
      timestamp of the remote path
      Throws:
      IOException
    • rename

      public boolean rename(String from, String to) throws IOException
      renames files on a remote server
      Specified by:
      rename in interface FtpSupportIntf
      Throws:
      IOException