Class AdvancedSSHSettings

java.lang.Object
com.enterprisedt.net.ftp.AdvancedSSHSettings

public class AdvancedSSHSettings extends Object
Advanced settings specifically for the SFTP (FTP over SSH) protocol. Generally these settings are not required for basic use of the protocol.

All settings must be set before connecting to the server.

Version:
$Revision$
Author:
Bruce Blackshaw
  • Method Details

    • getSSHServerValidator

      public SSHFTPValidator getSSHServerValidator()
      Returns a reference to the host validator, which validates the server's public key.
      Returns:
      Returns the host validator.
    • setSSHServerValidator

      public void setSSHServerValidator(SSHFTPValidator validator)
      Sets the host validator, which validates the server's public key.
      Parameters:
      validator - new validator
    • isDisableWaitForChannelClose

      public boolean isDisableWaitForChannelClose()
      Is waiting for server acknowledge on closure of a channel disabled?
      Returns:
      true if disabled, false otherwise
    • setDisableWaitForChannelClose

      public void setDisableWaitForChannelClose(boolean disableWaitForChannelClose) throws FTPException
      Disables waiting for an acknowledgement from the server when the client has requested that a channel be closed.
      Parameters:
      disableWaitForChannelClose - true to disable the wait
      Throws:
      FTPException
    • checkDirReadableForChDir

      public boolean checkDirReadableForChDir()
      Check that a directory is readable prior to changing into it. The default is true.
      Returns:
      true if we perform the readable check, false otherwise
    • setCheckDirReadableForChDir

      public void setCheckDirReadableForChDir(boolean checkDirReadableForChDir)
      Set the flag that determines if a check is made when changing into a directory to see if the directory is readable.
    • isDisableChModAfterPut

      public boolean isDisableChModAfterPut()
      Is the permission change made after creating a file (which is done to ensure the permissions are correct) disabled or not? Some servers return an error saying the file does not exist
    • setDisableChModAfterPut

      public void setDisableChModAfterPut(boolean disableChmodAfterPut) throws FTPException
      Set the permission change made after creating a file (which is done to ensure the permissions are correct) to disabled or enabled. The default is false, i.e. permission change is not disabled.
      Parameters:
      disableChmodAfterPut - true to disable the permission change
      Throws:
      FTPException
    • isDisableChModAfterCreateDir

      public boolean isDisableChModAfterCreateDir()
      Is the permission change made after creating a directory (which is done to ensure the permissions are correct) disabled or not? Some servers return an error saying the file does not exist
    • setDisableChModAfterCreateDir

      public void setDisableChModAfterCreateDir(boolean disableChmodAfterCreateDir) throws FTPException
      Set the permission change made after creating a directory (which is done to ensure the permissions are correct) to disabled or enabled. The default is false, i.e. permission change is not disabled.
      Parameters:
      disableChmodAfterPut - true to disable the permission change
      Throws:
      FTPException
    • isRekeyEnabled

      public boolean isRekeyEnabled()
      Is re-keying after 1 GB enabled? If enabled (the default), after 1 GB of transfer a new set of cryptographic keys are established. This is a security measure, not supported by all servers.
      Returns:
      true if enabled (the default)
    • setRekeyEnabled

      public void setRekeyEnabled(boolean enableRekey)
      Set flag to disable or enable re-keying after 1 GB
      Parameters:
      enableRekey - true to enable, false to disable
    • isParallelWriteMode

      public boolean isParallelWriteMode()
      Is parallel write mode being used? Switch it off if any problems are experienced. It is faster but can cause problems with some servers
      Returns:
      true if parallel write mode (default)
    • setParallelWriteMode

      public void setParallelWriteMode(boolean parallelWriteMode) throws FTPException
      Set parallel write mode on or off. Switch it off if any problems are experienced. It is faster but can cause problems with some servers
      Parameters:
      parallelWriteMode - true to enable, false to disable
      Throws:
      FTPException
    • getMaxQueuedReadRequests

      public int getMaxQueuedReadRequests()
      Returns:
      the maximum number of requests to send
    • setMaxQueuedReadRequests

      public void setMaxQueuedReadRequests(int maxQueuedReadRequests) throws FTPException
      In SFTP, files are read block-by-block. The client sends one request per block. Queueing up read-requests helps to counteract latencies. This property determines the number of read-requests that should be queued up. If it's set to 1 then no requests are queued up meaning that reads are done synchronously. The default is 32.
      Parameters:
      maxQueuedReadRequests - the maximum number of requests to send
      Throws:
      FTPException
    • getPrivateKeyFile

      public String getPrivateKeyFile()
      Get the path of the file from which the client's private key was read (if setPrivateKeyFile was previously called). The private key is used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Returns:
      path to file, or null if not set
    • setPrivateKeyFile

      public void setPrivateKeyFile(String privateKeyFileName) throws FTPException
      Read the client's private key file, used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Parameters:
      privateKeyFileName - path to file
      Throws:
      FTPException - Thrown if an error occurs while reading the private key.
    • getPrivateKeyInputStream

      public InputStream getPrivateKeyInputStream()
      Returns an InputStream for the client's private key, used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Returns:
      reference to InputStream, or null if not set
    • setPrivateKeyInputStream

      public void setPrivateKeyInputStream(InputStream privateKeyInputStream) throws FTPException
      Read the client's private key from the given InputStream. The private key is used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Parameters:
      privateKeyInputStream - InputStream from which the private key can be read
      Throws:
      FTPException - Thrown if an error occurs while reading the private key.
    • getPrivateKeyBytes

      public byte[] getPrivateKeyBytes()
      Returns a byte-array containing the client's private key if one has been set. The private key is used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Returns:
      Byte-array containing the client's private key, or null if not set
    • setPrivateKeyBytes

      public void setPrivateKeyBytes(byte[] privateKeyBytes) throws FTPException
      Reads the client's private key from the given byte-array. The private key is used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.
      Parameters:
      privateKeyBytes - Byte-array containing the client's private key
      Throws:
      FTPException - Thrown if an error occurs while parsing the private key.
    • getPrivateKeyFilePassphrase

      public String getPrivateKeyFilePassphrase()
      Get the passphrase for the private key file.
      Returns:
      passphrase
    • setPrivateKeyFilePassphrase

      public void setPrivateKeyFilePassphrase(String privateKeyFilePassphrase) throws FTPException
      Set the passphrase for the private key file.
      Parameters:
      privateKeyFilePassphrase - passphrase to set
      Throws:
      FTPException
    • isCompressionDelayed

      public boolean isCompressionDelayed()
      Is compression set to be delayed until after authentication? The default is to allow the server to decide, i.e. both 'zlib' and 'zlib@openssh.com' are sent to the server. Setting this to true means only 'zlib@openssh.com' is sent to the server (if compression is enabled).
      Returns:
      true if delayed
    • setCompressionDelayed

      public void setCompressionDelayed(boolean compressionDelayed) throws FTPException
      Set flag to force compression delayed until after authentication (if indeed compression is to be used).
      Parameters:
      compressionDelayed - true to delay compression until after AUTH_SUCCESS
      Throws:
      FTPException
    • getEnabledAlgorithms

      public SSHFTPAlgorithm[] getEnabledAlgorithms()
      Returns an array containing all enabled algorithms (of all types).
      Returns:
      An array of all enabled algorithms.
    • getEnabledAlgorithms

      public SSHFTPAlgorithm[] getEnabledAlgorithms(int algorithmType) throws SSHFTPException
      Returns an array containing all enabled algorithms of a particular type.
      Parameters:
      algorithmType - Type of algorithms to return (See SSHFTPAlgorithm).
      Returns:
      An array of all enabled algorithms of the given type.
      Throws:
      SSHFTPException - Thrown if the given algorithm-type is invalid.
    • disableAllAlgorithms

      public void disableAllAlgorithms(int algorithmType) throws FTPException
      Disables all algorithms of a particular type. Note that one algorithm of each type must be enabled before you can connect to a server.
      Parameters:
      algorithmType - Type of algorithms to return (See SSHFTPAlgorithm).
      Throws:
      FTPException
    • disableAllAlgorithms

      public void disableAllAlgorithms() throws FTPException
      Disables all algorithms. Note that one algorithm of each type must be enabled before you can connect to a server.
      Throws:
      FTPException
    • setAlgorithmEnabled

      public void setAlgorithmEnabled(SSHFTPAlgorithm algorithm, boolean enable) throws FTPException
      Enable/disable the given algorithm.
      Parameters:
      algorithm - Algorithm to enable/disable.
      enable - Flag indicating whether the algorithm should be enabled or disabled.
      Throws:
      FTPException
    • getMaxPacketSize

      public int getMaxPacketSize()
      Get the max packet size set
      Returns:
      -1 if not set, or else the set size
    • setMaxPacketSize

      public void setMaxPacketSize(int maxPacketSize) throws FTPException
      Set the maximum packet size. This should be used if errors are being received such as "packet too long: xxxx". Set the size smaller than the size listed in the error message.
      Parameters:
      maxPacketSize - size to set
      Throws:
      FTPException
    • getUmask

      public String getUmask()
      Get the current umask used for creating files
      Returns:
      current umask as octal string
    • setUmask

      public void setUmask(String umask)
      Sets the umask used for permissions when creating files
      Parameters:
      umask - umask as 4 digit octal, e.g. 0022
      Throws:
      FTPException
    • getAuthenticationType

      public SSHAuthenticationType getAuthenticationType()
      Get the type of authentication that is set up to be used.
      Returns:
      SSHAuthenticationType
    • setAuthenticationType

      public void setAuthenticationType(SSHAuthenticationType sshAuthenticationType) throws FTPException
      Set the authentication type to be used. Different fields need to be set depending on the type use, e.g. SSHAuthenticationType.PUBLIC_KEY requires the client's private key and passphrase to be set.
      Parameters:
      sshAuthenticationType - authentication type to be used
      Throws:
      FTPException
    • getSSHAuthPrompts

      public SSHAuthPrompt[] getSSHAuthPrompts()
      Get the array of authentication prompts that are to be used for keyboard-interactive authentication.
      Returns:
      array of prompts
    • setSSHAuthPrompts

      public void setSSHAuthPrompts(SSHAuthPrompt[] authPrompts) throws FTPException
      Set the array of authentication prompts that are to be used for keyboard-interactive authentication.
      Parameters:
      authPrompts - prompts to set up
      Throws:
      FTPException
    • isPortsInKnownHosts

      public boolean isPortsInKnownHosts()
      Are non-standard port numbers used in known_hosts files? If so then hosts are stored as [hostname]:port if the port number is not 22.

      Default is true.

      Returns:
      true if non-standard ports used in known_hosts
    • setPortsInKnownHosts

      public void setPortsInKnownHosts(boolean portsInKnownHosts) throws FTPException
      Change whether or not non-standard port numbers are used in known_hosts files. If so then hosts are stored as [hostname]:port if the port number is not 22.
      Parameters:
      portsInKnownHosts - true to enable, false to disable
      Throws:
      FTPException
    • setRemoteEOL

      public void setRemoteEOL(String remoteEOL) throws FTPException
      Set a remoteEOL to be forced, irrespective of what is detected from server information. This method must be called before connecting.
      Parameters:
      remoteEOL - remoteEOL to force
      Throws:
      FTPException
    • getRemoteEOL

      public String getRemoteEOL()
      Get the remote EOL string that is forced to be used irrespective of what is detected from server information.
      Returns:
      String, or null if autodetect is to be used