Class SftpSession

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

public class SftpSession extends Object implements FtpSupportIntf
Network Mediation User: jwu Date: Aug 8, 2003 Time: 9:50:24 AM MetaSolv Software Inc.
  • Constructor Details

    • SftpSession

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

      public SftpSession(String host, String login, String password, LoggerIfc logger)
      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
    • SftpSession

      public SftpSession(String host, int port, String login, String password, String hostsFile, LoggerIfc logger)
      Creates an FtpSession object with the given host, login and password.
      Parameters:
      host - remote host (ip or hostname)
      port - Ftp port number, default is 22 for SFTP
      login - login name
      password - login password
      hostsFile - Hosts file
      logger - event logger
  • Method Details

    • 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
    • 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
    • setTimeout

      public void setTimeout(long 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
    • listDirectories

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

      public Date getTimestamp(String remotePath) throws IOException
      Returns the timestamp of the given remote path.
      Specified by:
      getTimestamp in interface FtpSupportIntf
      Parameters:
      remotePath - 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