Secure iNet Factory

com.jscape.inet.ftps
Class Ftps

java.lang.Object
  extended bycom.jscape.inet.ftps.Ftps

public class Ftps
extends java.lang.Object

Implements the basic functionality of a FTPS (FTP over SSL) client.

Example Usage:

 // create new Ftps instance
 Ftps ftps = new Ftps("ftp.myserver.com","jsmith","secret");
 try {
 // establish connection
 ftps.connect();
 

// print out directory listing System.out.println(ftps.getDirListingAsString());

// disconnect from FTPS server ftps.disconnect(); } catch(Exception e) { System.out.println(e); }


Nested Class Summary
static interface Ftps.ConnectionStrategy
          The FTP client connection strategy.
 
Field Summary
static int ASCII
          Flag to indicate that ASCII transfer mode is used.
static Ftps.ConnectionStrategy AUTH_SSL
          Connection type for AUTH SSL FTP session.
static Ftps.ConnectionStrategy AUTH_TLS
          Connection type for AUTH TLS FTP session (default).
static int AUTO
          Flag to indicate that automatic transfer mode detection is used.
static int BINARY
          Flag to indicate that BINARY transfer mode is used.
static java.lang.String CURRENT_DIR
          Represents the current directory.
static Ftps.ConnectionStrategy IMPLICIT_SSL
          Connection type for implicit SSL session.
static java.lang.String UP_DIR
          Represents the parent directory of current directory.
 
Constructor Summary
Ftps()
          Creates a new Ftps instance.
Ftps(java.lang.String host, java.lang.String user, java.lang.String pwd)
          Creates a new Ftps instance.
Ftps(java.lang.String host, java.lang.String user, java.lang.String pwd, java.io.File localDirectory)
          Creates new Ftp instance.
Ftps(java.lang.String host, java.lang.String user, java.lang.String pwd, int port)
          Creates a new Ftp instance.
Ftps(java.lang.String host, java.lang.String user, java.lang.String pwd, java.lang.String account)
          Creates a new Ftps instance.
 
Method Summary
 void addFtpListener(FtpListener listener)
          Adds FTP event listener.
 void addFtpsCertificateVerifier(FtpsCertificateVerifier listener)
          Deprecated. see setFtpsCertificateVerifier(FtpsCertificateVerifier)
 void changePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Changes the password for current account.
 boolean checksum(byte[] data, java.lang.String remoteFile)
          Compares checksum of the local data and remote file.
 boolean checksum(java.io.File localfile, java.lang.String remoteFile)
          Compares checksum of the local and remote files.
 void clearCommandChannel()
          Clears command channel.
 void clearProxySettings()
          Clears proxy server values.
 void connect()
          Connects to FTP server and performs login.
 void connect(boolean login)
          Connects to FTP server and optionally performs login.
 void deleteDir(java.lang.String remoteDirectory)
          Deletes directory from FTP server.
 void deleteDir(java.lang.String remoteDirectory, boolean recurse)
          Deletes directory from FTP server.
 void deleteFile(java.lang.String remoteFile)
          Deletes remote file from FTP server.
 void disconnect()
          Quits the FTP session and disconnects from the FTP server.
 void download(java.io.OutputStream out, java.lang.String remoteFile)
          Downloads file from FTP server and writes contents to provided OutputStream.
 java.io.File download(java.lang.String remoteFile)
          Downloads file from FTP server.
 java.io.File download(java.lang.String localFile, java.lang.String remoteFile)
          Downloads file from FTP server.
 void downloadDir(java.lang.String remoteDir)
          Downloads remote directory and contents recursively from FTP server.
 void downloadDir(java.lang.String remoteDir, int retryLimit, boolean performChecksum)
          Downloads remote directory and contents recursively from FTP server.
 java.lang.String getAccount()
          Gets optional account of FTP server.
 int getBlockTransferSize()
          Gets blocksize for use in transferring files.
 java.lang.String getCharacterEncoding()
          Deprecated. use the getWireEncoding method
 boolean getCompression()
          Gets whether the data is compressed during the transfering.
 boolean getConnectBeforeCommand()
          Gets whether connection will be established before sending data transfer command.
 Ftps.ConnectionStrategy getConnectionType()
          Returns the current connection type.
 javax.net.ssl.SSLContext getContext()
          Obtains the current SSL context.
 java.lang.String getContextAlgorithm()
          Gets algorithm used for SSL communications in default context.
 java.lang.String getContextAlgorithmProvider()
          Gets provider used for X509 algorithm in default context.
 java.lang.String getContextKeystoreProvider()
          Gets keystore provider used for default context.
 java.lang.String getContextProtocol()
          Gets protocol used for SSL communications in default context.
 java.lang.String getContextProtocolProvider()
          Gets provider used for TLS protocol in default context.
 int getDataPort()
          Deprecated. Replaced by getDataPortStart and getDataPortEnd
 int getDataPortEnd()
          Gets the data port end range for incoming non-passive (active) data connections.
 int getDataPortStart()
          Gets the data port start range for incoming non-passive (active) data connections.
 boolean getDebug()
          Gets debugging state.
 java.io.PrintStream getDebugStream()
          Gets PrintStream used in reporting debug statements.
 java.lang.String getDir()
          Gets current working directory of FTP server.
 java.util.Enumeration getDirListing()
          Gets directory listing from FTP server.
 java.util.Enumeration getDirListing(java.lang.String filter)
          Gets file listing of files matching filter criteria.
 java.lang.String getDirListingAsString()
          Gets raw directory listing of files on FTP server.
 java.lang.String getDirListingAsString(java.lang.String filter)
          Gets raw directory listing of files matching filter criteria.
 java.util.Enumeration getDirListingRegex(java.lang.String regex)
          Gets directory listing from FTP server returning only file and directory names that match the regular expression.
 java.lang.String getDiskEncoding()
          Gets character encoding used when reading data from disk for ASCII file transfer.
 java.lang.String[] getEnabledCiphers()
          Returns user-defined enabled SSL cipher suites.
 boolean getErrorOnSizeCommand()
          Gets whether an exception should be thrown when downloading a file and server does not support SIZE command.
 java.util.Enumeration getFeatures()
          Returns supported server features.
 long getFilesize(java.lang.String remoteFile)
          Gets filesize of remote file from FTP server as represented in ASCII.
 java.util.Date getFileTimestamp(java.lang.String remoteFile)
          Gets date/timestamp of remote file from FTP server.
 FtpFileParser getFtpFileParser()
          Gets the FtpFileParser used to parse directory listing returned when invoking Ftp#getDirListing method.
 FtpsCertificateVerifier getFtpsCertificateVerifier()
          Gets FTPS certificate verifier.
 java.lang.String getHostname()
          Gets hostname of FTP server.
 java.io.InputStream getInputStream(java.lang.String remoteFile, long offset)
          Gets a InputStream from FTP server for the purposes of downloading a file.
 int getLinger()
          Gets the linger time for closing data sockets.
 java.lang.String getLocalChecksum(java.io.File localFile)
          Returns local checksum.
 java.io.File getLocalDir()
          Gets local directory to be used in FTP session.
 java.util.Enumeration getLocalDirListing()
          Gets local directory listing.
 java.util.Enumeration getMachineDirListing(java.lang.String dirname)
          Gets directory listing using MLSD command.
 java.util.Enumeration getMachineDirListing(java.lang.String dirname, java.lang.String regex)
          Gets file listing of specified directory using MLSD command.
 FtpFile getMachineFileListing(java.lang.String filename)
          Gets the file description for the specified filename using MLST command.
 int getMode()
          Gets data transfer mode for current session.
 java.util.Enumeration getNameListing()
          Gets directory listing of files on FTP server using NLST command.
 java.util.Enumeration getNameListing(java.lang.String filter)
          Gets directory listing of files on FTP server matching filter criteria and using NLST command.
 java.io.OutputStream getOutputStream(java.lang.String fileName, long off, boolean append)
          Gets an OutputStream from FTP server for the purposes of uploading a file.
 boolean getPassive()
          Gets whether passive mode should be used.
 java.lang.String getPassword()
          Returns current FTP user password.
 int getPort()
          Gets port of FTP server.
 java.lang.String getPortAddress()
          Gets the external address to use when using active connections.
 java.lang.String getRemoteFileChecksum(java.lang.String remoteFile)
          Returns remote file checksum.
 int getResponseCode()
          Gets response code from last FTP command.
 boolean getShutdownCCC()
          Gets whether SSL connection should be shutdown after successfully issuing CCC command.
 java.lang.String getSystemType()
          Gets the system type of remote FTP server.
 int getTimeout()
          Gets the timeout for opening connection to FTP server.
 boolean getUseEPSV()
          Gets whether to use EPSV or PASV command for data tranfers.
 java.lang.String getUsername()
          Gets username of FTP user.
 java.lang.String getWireEncoding()
          Gets character encoding used when issuing commands and reading files from FTP server in ASCII mode.
 void interrupt()
          Interrupts the current data transfer and sets interrupted flag to true.
 boolean interrupted()
          Checks if transfer process was interrupted.
 boolean isConnected()
          Checks if client is connected to FTP server.
 boolean isFeatureSupported(java.lang.String command)
          Looks for the command argument into the server features list to validate if it is supported.
 java.lang.String issueCommand(java.lang.String cmd)
          Issues the command to FTP server.
 java.lang.String issueCommandCheck(java.lang.String cmd)
          Issues command to FTP server.
 void login()
          Logs into FTP server after establishing a connection.
 void makeDir(java.lang.String newDirectory)
          Makes directory on FTP server.
 void makeDirRecursive(java.lang.String newDirectory)
          Makes directory on FTP server, creating subdirectories if necessary.
 java.io.File makeLocalDir(java.lang.String directoryName)
          Creates local directory.
 void mdelete(java.lang.String filter)
          Deletes multiple files matching regular in FTP server's current directory.
 void mdownload(java.util.Enumeration fileNames)
          Downloads specified files in current working remote directory from FTP server to local directory.
 void mdownload(java.lang.String filter)
          Downloads multiple files matching regular expression from FTP server's current directory.
 void mupload(java.util.Enumeration fileNames)
          Uploads multiple files to FTP server Uploads are performed relative to current local directory.
 void mupload(java.lang.String filter)
          Uploads multiple files matching regular expression to FTP server's current directory.
 java.lang.String noop()
          Sends a NOOP (No Operation) command to FTP server.
 java.lang.String readResponse()
          Reads response from FTP server.
 void removeFtpListener(FtpListener listener)
          Removes specified FTP event listener.
 void renameFile(java.lang.String remoteFile, java.lang.String newFile)
          Renames remote file on FTP server.
 void reset()
          Resets the interrupted flag to false.
 java.io.File resumeDownload(java.lang.String remoteFile, long off)
          Resumes download of file from FTP server.
 java.io.File resumeDownload(java.lang.String localFile, java.lang.String remoteFile, long off)
          Resumes download of file from FTP server.
 void resumeUpload(java.io.File localFile, long off)
          Resumes upload of file to FTP server.
 void resumeUpload(java.io.File localFile, java.lang.String remoteFile, long off)
          Resumes upload of file to FTP server.
 void resumeUpload(java.lang.String localFile, long off)
          Resumes upload of file to FTP server.
 void resumeUpload(java.lang.String localFile, java.lang.String remoteFile, long off)
          Resumes upload of file to FTP server.
 void setAccount(java.lang.String account)
          Sets optional account of FTP server.
 void setAscii()
          Sets data transfer mode to ASCII.
 void setAuto(boolean auto)
          Sets data transfer mode to automatic detect.
 void setBinary()
          Sets data transfer mode to binary.
 void setBlockTransferSize(int blockSize)
          Sets block size for use in transferring files.
 void setCharacterEncoding(java.lang.String encoding)
          Deprecated. use the setWireEncoding method
 void setClientCertificates(java.security.KeyStore keystore, java.lang.String password)
          Sets optional client certificate to be used during authentication.
 void setClientCertificates(java.lang.String filename, java.lang.String password)
          Sets optional client certificate to be used during authentication.
 void setClientCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional client certificate to be used during authentication.
 void setCompression(boolean compression)
          Sets whether the data will be compressed during the transfer.
 void setConnectBeforeCommand(boolean value)
          Gets whether connection will be established before sending data transfer command.
 void setConnectionType(Ftps.ConnectionStrategy connectionType)
          Sets the connection type.
 void setContext(javax.net.ssl.SSLContext context)
          Sets the current SSL context.
 void setContextAlgorithm(java.lang.String algorithm)
          Sets algorithm used for SSL communications in default context.
 void setContextAlgorithmProvider(java.lang.String provider)
          Sets provider used for X509 algorithm in default context.
 void setContextKeystoreProvider(java.lang.String provider)
          Sets provider used for keystore in default context.
 void setContextProtocol(java.lang.String protocol)
          Sets protocol used for SSL communications in default context.
 void setContextProtocolProvider(java.lang.String provider)
          Sets provider used for TLS protocol in default context.
 void setDataPort(int dataPort)
          Deprecated. Replaced by setDataPortRange
 void setDataPortRange(int dataPortStart, int dataPortEnd)
          Sets the data port range for incoming non-passive (active) connections.
 void setDebug(boolean debug)
          Sets debugging state.
 void setDebugStream(java.io.PrintStream debugStream)
          Sets PrintStream used in reporting debug statements.
 void setDir(java.lang.String remoteDirectory)
          Sets current directory on FTP server.
 void setDirUp()
          Sets current directory on FTP server to parent directory.
 void setDiskEncoding(java.lang.String encoding)
          Sets character set used when reading data from disk for ASCII file transfer.
 void setEnabledCiphers(java.lang.String[] enabledCiphers)
          Sets user-defined enabled SSL cipher suites.
 void setErrorOnSizeCommand(boolean error)
          Sets whether an exception should be thrown when downloading a file and server does not support SIZE command.
 void setFileCreationTime(java.lang.String remoteName, java.util.Date date)
          Sets file creation time with a new value.
 void setFileModificationTime(java.lang.String remoteName, java.util.Date date)
          Sets the file modification time with a new value.
 void setFileTimestamp(java.lang.String remoteName, java.util.Date dateFile)
          Sets date/timestamp of remote file from FTP server.
 void setFtpFileParser(FtpFileParser parser)
          Sets the FtpFileParser used to parse directory listing returned when invoking Ftps#getDirListing method.
 void setFtpsCertificateVerifier(FtpsCertificateVerifier listener)
          Sets FTPS certificate verifier.
 void setHostname(java.lang.String host)
          Sets hostname of FTP server.
 void setLinger(int linger)
          Sets the linger time for closing data sockets.
 void setLocalDir(java.io.File localDirectory)
          Sets local directory to be used in FTP session.
 void setNATAddress(java.lang.String ipAddress)
          Sets a NAT address which will be used for PASV file transfers.
 void setPassive(boolean passive)
          Sets whether passive mode should be used.
 void setPassword(java.lang.String password)
          Sets password of FTP user.
 void setPort(int port)
          Sets port of FTP server.
 void setPortAddress(java.lang.String string)
          Sets the external address to use when using active connections using the PORT command.
 void setProtectionLevel(char level)
          Changes the protection level.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the username and password to use when for authentication with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this FTPS connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this FTPS connection.
 void setReceiveBufferSize(int receiveBufferSize)
          Sets the receive buffer size option of the ftps connection.
 void setSendBufferSize(int sendBufferSize)
          Sets the send buffer size option of the ftps connection.
 void setServerCertificates(java.security.KeyStore keystore)
          Sets optional server certificate to be used during authentication.
 void setServerCertificates(java.lang.String filename, java.lang.String password)
          Sets optional server certificate to be used during authentication.
 void setServerCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional server certificate to be used during authentication.
 void setShutdownCCC(boolean shutdownCCC)
          Sets whether SSL connection should be shutdown after successfully issuing CCC command.
 void setTimeout(int timeout)
          Sets the timeout for opening connection to FTP server.
 void setUseEPSV(boolean useEPSV)
          Sets whether to use EPSV or PASV command for data tranfers.
 void setUsername(java.lang.String user)
          Sets username of FTP user.
 void setWireEncoding(java.lang.String encoding)
          Sets character set used when issuing commands and transferring files in ASCII mode.
 void upload(byte[] data, java.lang.String remoteFile)
          Uploads file to FTP server where contents of file is not on disk but in memory.
 void upload(byte[] data, java.lang.String remoteFile, boolean append)
          Uploads file to FTP server where contents of file is not on disk but in memory.
 void upload(java.io.File localFile)
          Uploads file to FTP server.
 void upload(java.io.File localFile, boolean append)
          Uploads file to FTP server.
 void upload(java.io.File localFile, java.lang.String remoteFile)
          Uploads file to FTP server.
 void upload(java.io.File localFile, java.lang.String remoteFile, boolean append)
          Uploads file to FTP server.
 void upload(java.io.InputStream input, java.lang.String remoteFile)
          Uploads contents of InputStream to FTP server.
 void upload(java.io.InputStream input, java.lang.String remoteFile, boolean append)
          Uploads contents of InputStream to FTP server.
 void upload(java.lang.String localFile)
          Uploads file to FTP server.
 void upload(java.lang.String localFile, boolean append)
          Uploads file to FTP server.
 void upload(java.lang.String extension, java.io.File localFile)
          Uploads file to FTP server using temporary extension, then renames file back to original name once uploaded.
 void upload(java.lang.String localFile, java.lang.String remoteFile)
          Uploads file to FTP server.
 void upload(java.lang.String localFile, java.lang.String remoteFile, boolean append)
          Uploads file to FTP server.
 void uploadDir(java.io.File localDir)
          Uploads local directory and contents recursively to FTP server.
 void uploadDir(java.io.File localDir, int retryLimit, boolean performChecksum)
          Uploads local directory and contents to FTP server.
 void uploadDir(java.io.File localDir, int retryLimit, boolean performChecksum, java.lang.String extension)
          Uploads local directory and contents to FTP server.
 void uploadDir(java.io.File localDir, java.lang.String extension)
          Uploads local directory and contents recursively to FTP server.
 java.lang.String uploadUnique(java.io.File file)
          Uploads the file which is created in the current directory under a name unique to that directory.
 java.lang.String uploadUnique(java.io.File file, boolean useFilenameAsSeed)
          Uploads the file which is created in the current directory under a name unique to that directory.
 java.lang.String uploadUnique(java.io.InputStream in, java.lang.String fileName)
          Uploads the file which is created in the current directory under a name unique to that directory.
 java.lang.String uploadUnique(java.lang.String fileName)
          Uploads the file which is created in the current directory under a name unique to that directory.
 java.lang.String uploadUnique(java.lang.String fileName, boolean useFilenameAsSeed)
          Uploads the file which is created in the current directory under a name unique to that directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO

public static final int AUTO
Flag to indicate that automatic transfer mode detection is used.

See Also:
getMode(), Constant Field Values

ASCII

public static final int ASCII
Flag to indicate that ASCII transfer mode is used.

See Also:
getMode(), Constant Field Values

BINARY

public static final int BINARY
Flag to indicate that BINARY transfer mode is used.

See Also:
getMode(), Constant Field Values

CURRENT_DIR

public static final java.lang.String CURRENT_DIR
Represents the current directory. Value of "."

See Also:
Constant Field Values

UP_DIR

public static final java.lang.String UP_DIR
Represents the parent directory of current directory. Value of ".."

See Also:
Constant Field Values

IMPLICIT_SSL

public static final Ftps.ConnectionStrategy IMPLICIT_SSL
Connection type for implicit SSL session.


AUTH_TLS

public static final Ftps.ConnectionStrategy AUTH_TLS
Connection type for AUTH TLS FTP session (default).


AUTH_SSL

public static final Ftps.ConnectionStrategy AUTH_SSL
Connection type for AUTH SSL FTP session.

Constructor Detail

Ftps

public Ftps()
Creates a new Ftps instance.


Ftps

public Ftps(java.lang.String host,
            java.lang.String user,
            java.lang.String pwd)
Creates a new Ftps instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP usZer

Ftps

public Ftps(java.lang.String host,
            java.lang.String user,
            java.lang.String pwd,
            java.lang.String account)
Creates a new Ftps instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
account - the optional account of FTP user or null if not needed

Ftps

public Ftps(java.lang.String host,
            java.lang.String user,
            java.lang.String pwd,
            int port)
Creates a new Ftp instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
port - the port of FTP server

Ftps

public Ftps(java.lang.String host,
            java.lang.String user,
            java.lang.String pwd,
            java.io.File localDirectory)
Creates new Ftp instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
localDirectory - the local directory to be used for uploading / downloading files
Method Detail

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the #clearProxySettings method.

Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this FTPS connection. To clear these settings invoke the #clearProxySettings method.

Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this FTPS connection.

Parameters:
proxyType - The proxy type. Valid values: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.


setAscii

public void setAscii()
              throws FtpException
Sets data transfer mode to ASCII. You must be connected to the FTP server prior to invoking this method.

Throws:
FtpException - if an I/O or FTP error occurs.

setAuto

public void setAuto(boolean auto)
             throws FtpException
Sets data transfer mode to automatic detect. Any files with a base Content-Type value of text will be transferred using ASCII, all other files will be transfered using binary.

Example: file.txt, Content-Type = text/plain, uploaded using ASCII
Example: image.jpg Content-Type = image/jpg, uploaded using binary

Parameters:
auto - true to turn automatic detect on false to turn off
Throws:
FtpException - if an I/O or Ftp related error occurs

setBinary

public void setBinary()
               throws FtpException
Sets data transfer mode to binary. You must be connected to the FTP server prior to invoking this method.

Throws:
FtpException - if an I/O or FTP error occurs.

setBlockTransferSize

public void setBlockTransferSize(int blockSize)
Sets block size for use in transferring files. Default block size is 8192 bytes.

Parameters:
blockSize - the block size in bytes

getBlockTransferSize

public int getBlockTransferSize()
Gets blocksize for use in transferring files. Default block size is 8192 bytes.

Returns:
blocksize in bytes

setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
Deprecated. use the setWireEncoding method

Sets character set used when issuing commands and transferring files. This is helpful in instances where the FTP server uses a different character encoding than that used by the FTP client.

Parameters:
encoding - the character encoding to be used

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Deprecated. use the getWireEncoding method

Gets character encoding used when issuing commands and transferring files.

Returns:
the character encoding to be used

setCompression

public void setCompression(boolean compression)
Sets whether the data will be compressed during the transfer.

Parameters:
compression - Compression indicator.

getCompression

public boolean getCompression()
Gets whether the data is compressed during the transfering. The data will be compressed if the Ftps server support this feature (MODE Z command)

Returns:
true data will be compressed, false otherwise.

setClientCertificates

public void setClientCertificates(java.security.KeyStore keystore,
                                  java.lang.String password)
                           throws FtpException
Sets optional client certificate to be used during authentication.

Parameters:
keystore - the JKS keystore containing certificates
password - the password for opening JKS keystore
Throws:
FtpException - if an error occurs opening keystore

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password)
                           throws FtpException
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password
Throws:
FtpException - if an I/O error occurs

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
                           throws FtpException
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12
Throws:
FtpException - if an I/O error occurs

setConnectBeforeCommand

public void setConnectBeforeCommand(boolean value)
Gets whether connection will be established before sending data transfer command.

Parameters:
value - true if should connect before sending data transfer command, false otherwise send the command in passive mode

getConnectBeforeCommand

public boolean getConnectBeforeCommand()
Gets whether connection will be established before sending data transfer command.

Returns:
true if should connect before sending data transfer command, false otherwise

isConnected

public boolean isConnected()
Checks if client is connected to FTP server. To check if FTP client is connected to FTP server a NOOP (No Operation) command is sent to the FTP server. If connection has been lost then a value of false will be returned and an FtpConnectionLostEvent will be fired to any subscribed FtpListener.

Returns:
true if connected false otherwise
See Also:
FtpConnectionLostEvent

setConnectionType

public void setConnectionType(Ftps.ConnectionStrategy connectionType)
Sets the connection type. Default connection type is Ftps.AUTH_TLS.

Parameters:
connectionType - the current connection type

getConnectionType

public Ftps.ConnectionStrategy getConnectionType()
Returns the current connection type. Default connection type is Ftps.AUTH_TLS.

Returns:
the current connection type

setContext

public void setContext(javax.net.ssl.SSLContext context)
Sets the current SSL context.

Parameters:
context - the new SSL context
See Also:
SSLContext

setContextKeystoreProvider

public void setContextKeystoreProvider(java.lang.String provider)
Sets provider used for keystore in default context.

Parameters:
provider - The provider

setContextProtocolProvider

public void setContextProtocolProvider(java.lang.String provider)
Sets provider used for TLS protocol in default context.

Parameters:
provider - the provider

setContextAlgorithmProvider

public void setContextAlgorithmProvider(java.lang.String provider)
Sets provider used for X509 algorithm in default context.

Parameters:
provider - the provider

getContextAlgorithmProvider

public java.lang.String getContextAlgorithmProvider()
Gets provider used for X509 algorithm in default context.

Returns:
algorithm provider

getContextKeystoreProvider

public java.lang.String getContextKeystoreProvider()
Gets keystore provider used for default context. Default is null.

Returns:
keystore provider

getContextProtocolProvider

public java.lang.String getContextProtocolProvider()
Gets provider used for TLS protocol in default context. Default is null.

Returns:
protocol provider

setContextAlgorithm

public void setContextAlgorithm(java.lang.String algorithm)
Sets algorithm used for SSL communications in default context. Default is SunX509.

Parameters:
algorithm - the algorithm

getContextAlgorithm

public java.lang.String getContextAlgorithm()
Gets algorithm used for SSL communications in default context. Default is SunX509.

Returns:
algorithm

setContextProtocol

public void setContextProtocol(java.lang.String protocol)
Sets protocol used for SSL communications in default context. Default is TLS.

Parameters:
protocol - the protocol

getContextProtocol

public java.lang.String getContextProtocol()
Gets protocol used for SSL communications in default context. Default is TLS.

Returns:
protocol

getContext

public javax.net.ssl.SSLContext getContext()
Obtains the current SSL context.

Returns:
the current SSL context
See Also:
SSLContext

setDataPort

public void setDataPort(int dataPort)
Deprecated. Replaced by setDataPortRange

Sets data port for incoming active PORT connections.

Parameters:
dataPort - active port

getDataPort

public int getDataPort()
Deprecated. Replaced by getDataPortStart and getDataPortEnd

Returns current port for incoming active PORT data connections.

Returns:
active port

getDataPortEnd

public int getDataPortEnd()
Gets the data port end range for incoming non-passive (active) data connections.

Returns:
the end data port range for incoming data connections

setDataPortRange

public void setDataPortRange(int dataPortStart,
                             int dataPortEnd)
Sets the data port range for incoming non-passive (active) connections.

Parameters:
dataPortStart - start data port range for incoming connections
dataPortEnd - end data port range for incoming connections

getDataPortStart

public int getDataPortStart()
Gets the data port start range for incoming non-passive (active) data connections.

Returns:
the start data port range for incoming data connections

setDebug

public void setDebug(boolean debug)
Sets debugging state. All debug statements are reported to debug stream. Default debug stream is System.out.

Parameters:
debug - true to turn debugging on
See Also:
setDebugStream(java.io.PrintStream)

getDebug

public boolean getDebug()
Gets debugging state.

Returns:
true if debugging is on

setDebugStream

public void setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements. Default PrintStream is System.out

Parameters:
debugStream - the PrintStream to send debug statements to
See Also:
PrintStream

getDebugStream

public java.io.PrintStream getDebugStream()
Gets PrintStream used in reporting debug statements. Default PrintStream is System.out.

Returns:
the PrintStream used in reporting debug statements
See Also:
PrintStream

setDir

public void setDir(java.lang.String remoteDirectory)
            throws FtpException
Sets current directory on FTP server.

Parameters:
remoteDirectory - the remote directory
Throws:
FtpException - if an I/O or FTP error occurs.

getDir

public java.lang.String getDir()
                        throws FtpException
Gets current working directory of FTP server.

Returns:
current directory
Throws:
FtpException - if an I/O or FTP error occurs.

getDirListing

public java.util.Enumeration getDirListing(java.lang.String filter)
                                    throws FtpException
Gets file listing of files matching filter criteria. When using this method filter is passed to server and server is responsible for parsing filter. Servers may vary in how they handle these filters. For a client side filter use the getDirListingRegex method which uses regular expressions to parse results of a directory listing. Parsers are included to handle UNIX, NT and VMS directory style listings. If you are connecting to a FTP server that does not use any of these listing formats then you can optionally develop your own parser by extending the FtpFileParser class, or use some of the alternative methods for obtaining a directory listing such as the getNameListing or getDirListingAsString methods.

Parameters:
filter - the regular expression filename filter
Returns:
an Enumeration of FtpFile objects
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
FtpFile, getDirListingAsString(String), getDirListingRegex(String), getNameListing(java.lang.String), FtpFileParser, UnixParser, NTParser, VMSParser

getDirListing

public java.util.Enumeration getDirListing()
                                    throws FtpException
Gets directory listing from FTP server. Parsers are included to handle UNIX, NT and VMS directory style listings. If you are connecting to a FTP server that does not use any of these listing formats then you can optionally develop your own parser by extending the FtpFileParser class, or use some of the alternative methods for obtaining a directory listing such as the getNameListing or getDirListingAsString methods.

Returns:
an Enumeration of FtpFile objects
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
FtpFile, getDirListingAsString(String), getNameListing(java.lang.String), FtpFileParser, UnixParser, NTParser, VMSParser

getDirListingAsString

public java.lang.String getDirListingAsString(java.lang.String filter)
                                       throws FtpException
Gets raw directory listing of files matching filter criteria. When using this method filter is passed to server and server is responsible for parsing filter. Servers may vary in how they handle these filters. For a client side filter use the getDirListingRegex method which uses regular expressions to parse results of a directory listing.

Parameters:
filter - a regular expression filename filter
Returns:
a directory listing
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
getDirListingRegex(String)

getDirListingRegex

public java.util.Enumeration getDirListingRegex(java.lang.String regex)
                                         throws FtpException
Gets directory listing from FTP server returning only file and directory names that match the regular expression. For example, to list all files with extension .java or .class the regex value should be ".+\\.(?:java|class)".

Parameters:
regex - regular expression used to obtain the file list
Returns:
file list which matches the regular expression
Throws:
FtpException - if an I/O or protocol error occurs.

getDirListingAsString

public java.lang.String getDirListingAsString()
                                       throws FtpException
Gets raw directory listing of files on FTP server.

Returns:
a directory listing
Throws:
FtpException - if an I/O or FTP error occurs.

setDirUp

public void setDirUp()
              throws FtpException
Sets current directory on FTP server to parent directory.

Throws:
FtpException - if an I/O or FTP error occurs.

setDiskEncoding

public void setDiskEncoding(java.lang.String encoding)
Sets character set used when reading data from disk for ASCII file transfer.

Parameters:
encoding - the character encoding to be used

getDiskEncoding

public java.lang.String getDiskEncoding()
Gets character encoding used when reading data from disk for ASCII file transfer.

Returns:
the character encoding to be used

setEnabledCiphers

public void setEnabledCiphers(java.lang.String[] enabledCiphers)
Sets user-defined enabled SSL cipher suites.

Parameters:
enabledCiphers - enabled SSL cipher suites or null for using system-default cipher suites set

getEnabledCiphers

public java.lang.String[] getEnabledCiphers()
Returns user-defined enabled SSL cipher suites.

Returns:
user-defined enabled SSL cipher suites or null if system-default cipher suites are used

setErrorOnSizeCommand

public void setErrorOnSizeCommand(boolean error)
Sets whether an exception should be thrown when downloading a file and server does not support SIZE command. The SIZE command is used to obtain the length of remote file for use in firing progress events. Default is false.

Parameters:
error - true if exception should be thrown, false otherwise

getErrorOnSizeCommand

public boolean getErrorOnSizeCommand()
Gets whether an exception should be thrown when downloading a file and server does not support SIZE command. The SIZE command is used to obtain the length of remote file for use in firing progress events. Default is false.

Returns:
true if exception is thrown when SIZE command is not supported an exception when it caused an error, false the error will be ignored.

isFeatureSupported

public boolean isFeatureSupported(java.lang.String command)
Looks for the command argument into the server features list to validate if it is supported.

Parameters:
command - the feature command to search for
Returns:
true if the command is found into the server feature list; false otherwise

getFeatures

public java.util.Enumeration getFeatures()
                                  throws FtpException
Returns supported server features.