Package com.enterprisedt.net.ftp
Class AdvancedSSHSettings
java.lang.Object
com.enterprisedt.net.ftp.AdvancedSSHSettings
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 Summary
Modifier and TypeMethodDescriptionbooleanCheck that a directory is readable prior to changing into it.voidDisables all algorithms.voiddisableAllAlgorithms(int algorithmType) Disables all algorithms of a particular type.Get the type of authentication that is set up to be used.Returns an array containing all enabled algorithms (of all types).getEnabledAlgorithms(int algorithmType) Returns an array containing all enabled algorithms of a particular type.intGet the max packet size setintbyte[]Returns a byte-array containing the client's private key if one has been set.Get the path of the file from which the client's private key was read (ifsetPrivateKeyFilewas previously called).Get the passphrase for the private key file.Returns an InputStream for the client's private key, used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.Get the remote EOL string that is forced to be used irrespective of what is detected from server information.Get the array of authentication prompts that are to be used for keyboard-interactive authentication.Returns a reference to the host validator, which validates the server's public key.getUmask()Get the current umask used for creating filesbooleanIs compression set to be delayed until after authentication? The default is to allow the server to decide, i.e.booleanIs 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 existbooleanIs 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 existbooleanIs waiting for server acknowledge on closure of a channel disabled?booleanIs parallel write mode being used? Switch it off if any problems are experienced.booleanAre 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.booleanIs re-keying after 1 GB enabled? If enabled (the default), after 1 GB of transfer a new set of cryptographic keys are established.voidsetAlgorithmEnabled(SSHFTPAlgorithm algorithm, boolean enable) Enable/disable the given algorithm.voidsetAuthenticationType(SSHAuthenticationType sshAuthenticationType) Set the authentication type to be used.voidsetCheckDirReadableForChDir(boolean checkDirReadableForChDir) Set the flag that determines if a check is made when changing into a directory to see if the directory is readable.voidsetCompressionDelayed(boolean compressionDelayed) Set flag to force compression delayed until after authentication (if indeed compression is to be used).voidsetDisableChModAfterCreateDir(boolean disableChmodAfterCreateDir) Set the permission change made after creating a directory (which is done to ensure the permissions are correct) to disabled or enabled.voidsetDisableChModAfterPut(boolean disableChmodAfterPut) Set the permission change made after creating a file (which is done to ensure the permissions are correct) to disabled or enabled.voidsetDisableWaitForChannelClose(boolean disableWaitForChannelClose) Disables waiting for an acknowledgement from the server when the client has requested that a channel be closed.voidsetMaxPacketSize(int maxPacketSize) Set the maximum packet size.voidsetMaxQueuedReadRequests(int maxQueuedReadRequests) In SFTP, files are read block-by-block.voidsetParallelWriteMode(boolean parallelWriteMode) Set parallel write mode on or off.voidsetPortsInKnownHosts(boolean portsInKnownHosts) Change whether or not non-standard port numbers are used in known_hosts files.voidsetPrivateKeyBytes(byte[] privateKeyBytes) Reads the client's private key from the given byte-array.voidsetPrivateKeyFile(String privateKeyFileName) Read the client's private key file, used for client authentication if SSHAuthenticationType.PUBLIC_KEY is being used.voidsetPrivateKeyFilePassphrase(String privateKeyFilePassphrase) Set the passphrase for the private key file.voidsetPrivateKeyInputStream(InputStream privateKeyInputStream) Read the client's private key from the given InputStream.voidsetRekeyEnabled(boolean enableRekey) Set flag to disable or enable re-keying after 1 GBvoidsetRemoteEOL(String remoteEOL) Set a remoteEOL to be forced, irrespective of what is detected from server information.voidsetSSHAuthPrompts(SSHAuthPrompt[] authPrompts) Set the array of authentication prompts that are to be used for keyboard-interactive authentication.voidsetSSHServerValidator(SSHFTPValidator validator) Sets the host validator, which validates the server's public key.voidSets the umask used for permissions when creating files
-
Method Details
-
getSSHServerValidator
Returns a reference to the host validator, which validates the server's public key.- Returns:
- Returns the host validator.
-
setSSHServerValidator
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
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
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
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
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
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
Get the path of the file from which the client's private key was read (ifsetPrivateKeyFilewas 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
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
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
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
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
Get the passphrase for the private key file.- Returns:
- passphrase
-
setPrivateKeyFilePassphrase
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
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
Returns an array containing all enabled algorithms (of all types).- Returns:
- An array of all enabled algorithms.
-
getEnabledAlgorithms
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
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
Disables all algorithms. Note that one algorithm of each type must be enabled before you can connect to a server.- Throws:
FTPException
-
setAlgorithmEnabled
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
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
Get the current umask used for creating files- Returns:
- current umask as octal string
-
setUmask
Sets the umask used for permissions when creating files- Parameters:
umask- umask as 4 digit octal, e.g. 0022- Throws:
FTPException
-
getAuthenticationType
Get the type of authentication that is set up to be used.- Returns:
- SSHAuthenticationType
-
setAuthenticationType
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
Get the array of authentication prompts that are to be used for keyboard-interactive authentication.- Returns:
- array of prompts
-
setSSHAuthPrompts
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
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
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
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
-