Secure FTP Factory

com.jscape.inet.ftp
Class Ftp

java.lang.Object
  extended by com.jscape.inet.ftp.Ftp

public class Ftp
extends java.lang.Object

Implements the basic functionality of a FTP client.

Example Usage:

 // create new Ftp instance
 Ftp ftp = new Ftp("ftp.myserver.com","anonymous","user@myserver.com");
 try {
 // connect to FTP server
 ftp.connect();
 

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

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


Field Summary
static int ASCII
          Flag to indicate that ASCII transfer mode is used.
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 java.lang.String UP_DIR
          Represents the parent directory of current directory.
 
Constructor Summary
Ftp()
          Creates a new Ftp instance.
Ftp(FtpImplementation impl)
          Creates Ftp instance for passed implementation.
Ftp(java.lang.String host, java.lang.String user, java.lang.String pwd)
          Creates a new Ftp instance.
Ftp(java.lang.String host, java.lang.String user, java.lang.String pwd, java.io.File localDirectory, FtpImplementation impl)
          Creates new Ftp instance.
Ftp(java.lang.String host, java.lang.String user, java.lang.String pwd, FtpImplementation impl)
          Creates a new Ftp instance.
Ftp(java.lang.String host, java.lang.String user, java.lang.String pwd, int port, FtpImplementation impl)
          Creates a new Ftp instance.
 
Method Summary
 void abortDownloadThreads()
          Abort all download threads.
 void abortUploadThreads()
          Cancel all upload threads.
 void addFtpListener(FtpListener listener)
          Adds FTP event listener.
 void changePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Changes 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 clearProxySettings()
          Clears proxy server values.
 void connect()
          Connects to FTP server and performs login using specified username, password and optional account.
 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 FTP session and disconnects from 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 from FTP server.
 void downloadDir(java.lang.String remoteDir, int retryLimit, boolean performChecksum, int threadCount)
          Download directory.
 void downloadDir(java.lang.String remoteDir, int retryLimit, int retryInterval, boolean performChecksum)
          Downloads remote directory and contents from FTP server.
 void downloadDir(java.lang.String remoteDir, int retryLimit, int retryInterval, boolean performChecksum, int threadCount)
          Downloads remote directory and contents from FTP server.
 java.lang.String getAccount()
          Gets optional account of FTP server.
 boolean getAutoDetectIpv6()
          Get auto detect Ipv6 detection mode.
 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 passive socket connection should be established before or after sending command to read data from passive connection.
 int getDataPort()
          Deprecated. replaced by getDataPortStart and getDataPortEnd methods.
 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 filter)
          Gets directory listing from FTP server returning only file and directory names that match the regular expression.
 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 using FEAT command.
 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.
 java.lang.String getHostname()
          Gets hostname of FTP server.
 java.io.InputStream getInputStream(java.lang.String remoteFile, long pos)
          Gets an InputStream from FTP server for the purposes of downloading a file.
 boolean getKeepAlive(boolean keepAlive)
          Get socket keep alive.
 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 file listing of specified directory 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.
 java.util.Enumeration getNameListing(java.lang.String filter)
          Gets directory listing of files on FTP server matching filter criteria and using NLST command.
 java.lang.String getNATAddress()
          Get the NAT address.
 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 IP address to use when listing for active connections using the PORT command.
 int getRecursiveDirectoryFileCount(java.lang.String directory)
          Get size of all files rescursively in a given remote directory.
 long getRecursiveDirectorySize(java.lang.String directory)
          Get size of all files rescursively in a given remote directory.
 java.lang.String getRemoteFileChecksum(java.lang.String remoteFile)
          Returns remote file checksum.
 java.util.Vector getRemoteFileList(java.lang.String remoteDir)
          Gets a remote file list fron the current directory.
 int getResponseCode()
          Gets response code from last FTP 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 getUseEPRT()
          Gets whether to use EPRT or PORT command for data tranfers.
 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 encoding set used when issuing commands and transferring files.
 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 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 expression 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 current directory.
 void mupload(java.util.Enumeration fileNames)
          Uploads multiple files to FTP server.
 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.
 void readResponse()
          Reads server response.
 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 be automatically detected.
 void setAutoDetectIpv6(boolean value)
          Set auto detect Ipv6 detection mode.
 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 setCompression(boolean compression)
          Sets whether the data will be compressed during the transfer.
 void setConnectBeforeCommand(boolean value)
          Sets whether passive socket connection should be established before or after sending command to read data from passive connection.
 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 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 remoteFile, java.util.Date dateFile)
          Sets date/timestamp of remote file on FTP server.
 void setFtpFileParser(FtpFileParser parser)
          Sets the FtpFileParser used to parse directory listing returned when invoking Ftp#getDirListing method.
 void setHostname(java.lang.String host)
          Sets hostname of FTP server.
 void setKeepAlive(boolean keepAlive)
          Set socket keep alive.
 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 IP address to use when listing for active connections using the PORT command.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the proxy authentication username and password to use with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this FTP connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this FTP connection.
 void setReceiveBufferSize(int receiveBufferSize)
          Sets the receive buffer size option of the ftp connection.
 void setSendBufferSize(int sendBufferSize)
          Sets the send buffer size option of the ftp connection.
 void setTimeout(int timeout)
          Sets the timeout for opening connection to FTP server.
 void setUseEPRT(boolean useEPRT)
          Sets whether to use EPRT or PASV command for data tranfers.
 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 encoding set used when issuing commands and transferring files.
 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 file to FTP server.
 void upload(java.io.InputStream input, java.lang.String remoteFile, boolean append)
          Uploads file 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 and renames the remote file name.
 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, int threadCount)
           
 void uploadDir(java.io.File localDir, int retryLimit, int retryInterval, boolean performChecksum, java.lang.String extension)
          Uploads local directory and contents to FTP server.
 void uploadDir(java.io.File localDir, int retryLimit, int retryInterval, boolean performChecksum, java.lang.String extension, int threadCount)
          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 file to FTP server storing remotely using a unique name.
 java.lang.String uploadUnique(java.io.File file, boolean useFilenameAsSeed)
          Uploads file to FTP server storing remotely using a unique name.
 java.lang.String uploadUnique(java.io.InputStream in, java.lang.String fileName)
          Uploads file to FTP server storing remotely using a unique name.
 java.lang.String uploadUnique(java.lang.String fileName)
          Uploads file to FTP server storing remotely using a unique name.
 java.lang.String uploadUnique(java.lang.String fileName, boolean useFilenameAsSeed)
          Uploads file to FTP server storing remotely using a unique name.
 
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
Constructor Detail

Ftp

public Ftp(FtpImplementation impl)
Creates Ftp instance for passed implementation.

Parameters:
impl - desired implementation.

Ftp

public Ftp()
Creates a new Ftp instance.


Ftp

public Ftp(java.lang.String host,
           java.lang.String user,
           java.lang.String pwd,
           FtpImplementation impl)
Creates a new Ftp instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
impl - desired implementation.

Ftp

public Ftp(java.lang.String host,
           java.lang.String user,
           java.lang.String pwd,
           int port,
           FtpImplementation impl)
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
impl - desired implementation.

Ftp

public Ftp(java.lang.String host,
           java.lang.String user,
           java.lang.String pwd,
           java.io.File localDirectory,
           FtpImplementation impl)
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
impl - desired implementation

Ftp

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

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

setAutoDetectIpv6

public void setAutoDetectIpv6(boolean value)
Set auto detect Ipv6 detection mode.

Parameters:
value -

getAutoDetectIpv6

public boolean getAutoDetectIpv6()
Get auto detect Ipv6 detection mode.

Returns:

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the proxy authentication username and password to use 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 FTP 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 to connect to
See Also:
clearProxySettings()

setProxyType

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

Parameters:
proxyType - The proxy type. Values allowed: 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)
Sets data transfer mode to be automatically detected. 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

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 blocksize is 4096 bytes

Parameters:
blocksize - the blocksize in bytes

getBlockTransferSize

public int getBlockTransferSize()
Gets blocksize for use in transferring files. Default blocksize is 4096 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

setConnectBeforeCommand

public void setConnectBeforeCommand(boolean value)
Sets whether passive socket connection should be established before or after sending command to read data from passive connection. Default is true.

Parameters:
value - true if connection should be established before command, false otherwise

getConnectBeforeCommand

public boolean getConnectBeforeCommand()
Gets whether passive socket connection should be established before or after sending command to read data from passive connection. Default is true.

Returns:
true if connection is established before 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

setDataPort

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

Sets data port for incoming active PORT connections. Default value is 0, assigning a random open port

Parameters:
dataPort - active port
See Also:
setDataPortRange(int, int)

getDataPort

public int getDataPort()
Deprecated. replaced by getDataPortStart and getDataPortEnd methods.

Returns current port for incoming active PORT data connections. Default value is 0, assigning a random open port.

Returns:
active port
See Also:
getDataPortStart(), getDataPortEnd()

getDataPortEnd

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

Returns:
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:
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 filename filter to be handled by server
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 - the filename filter to be handled by server
Returns:
an String containing raw directory listing contents
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
getDirListingRegex(String)

getDirListingAsString

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

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

getDirListingRegex

public java.util.Enumeration getDirListingRegex(java.lang.String filter)
                                         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:
filter - 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.

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.

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

isFeatureSupported

public boolean isFeatureSupported(java.lang.String command)
                           throws FtpException
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
Throws:
FtpException - if an I/O or FTP error occurs

getFeatures

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

Returns:
an Enumeration of features Strings
Throws:
FtpException - if an I/O or FTP error occurs

setFileTimestamp

public void setFileTimestamp(java.lang.String remoteFile,
                             java.util.Date dateFile)
                      throws FtpException
Sets date/timestamp of remote file on FTP server. This feature is not supported by RFC-959 so may not work on all FTP servers.

Parameters:
remoteFile - the remote file
dateFile - the date/timestamp of remote file
Throws:
FtpException - if an I/O or FTP error occurs.

getFileTimestamp

public java.util.Date getFileTimestamp(java.lang.String remoteFile)
                                throws FtpException
Gets date/timestamp of remote file from FTP server. This feature is not supported by RFC-959 so may not work on all FTP servers.

Parameters:
remoteFile - the remote file
Returns:
date the date/timestamp of remote file
Throws:
FtpException - if an I/O or FTP error occurs.

setFileCreationTime

public void setFileCreationTime(java.lang.String remoteName,
                                java.util.Date date)
                         throws FtpException
Sets file creation time with a new value. This command is not specified in RFC 959 and it is not support by many Ftp servers.

Parameters:
remoteName - the remote file name
date - the new creation time
Throws:
FtpException - If an error occurs.

setFileModificationTime

public void setFileModificationTime(java.lang.String remoteName,
                                    java.util.Date date)
                             throws FtpException
Sets the file modification time with a new value. This command is not specified in RFC 959 and it is not support by many Ftp servers.

Parameters:
remoteName - the remote file
date - the new modification time
Throws:
FtpException - If an error occurs

getFilesize

public long getFilesize(java.lang.String remoteFile)
                 throws FtpException
Gets filesize of remote file from FTP server as represented in ASCII. This feature is not supported by RFC-959 so may not work on all FTP servers. For larger files it may take some time to return as server will often convert file to ASCII before returning a filesize.

Parameters:
remoteFile - the remote file
Returns:
filesize in bytes
Throws:
FtpException - if an I/O or FTP error occurs.

setFtpFileParser

public void setFtpFileParser(FtpFileParser parser)
Sets the FtpFileParser used to parse directory listing returned when invoking Ftp#getDirListing method. If FtpFileParser is null upon establishing connection the Ftp class will attempt to determine the proper FtpFileParser based on information retrieved from the FTP server. If the FtpFileParser is null and cannot be determined otherwise then by default an instance of UnixParser will be used. Upon disconnecting from FTP server the FtpFileParser will be reset to null.

Parameters:
parser - a FtpFileParser instance
See Also:
FtpFileParser, UnixParser, NTParser, VMSParser

getFtpFileParser

public FtpFileParser getFtpFileParser()
Gets the FtpFileParser used to parse directory listing returned when invoking Ftp#getDirListing method. If FtpFileParser is null upon establishing connection the Ftp class will attempt to determine the proper FtpFileParser based on information retrieved from the FTP server. If the FtpFileParser is null and cannot be determined otherwise then by default an instance of UnixParser will be used. Upon disconnecting from FTP server the FtpFileParser will be reset to null.

Returns:
a FtpFileParser or null if no FtpFileParser has been defined.
See Also:
FtpFileParser, UnixParser, NTParser, VMSParser

setHostname

public void setHostname(java.lang.String host)
Sets hostname of FTP server.

Parameters:
host - the hostname or IP address of FTP server

setAccount

public void setAccount(java.lang.String account)
Sets optional account of FTP server. This should not be confused with username.

Parameters:
account - the account
See Also:
setUsername(String)

getAccount

public java.lang.String getAccount()
Gets optional account of FTP server. This should not be confused with username.

Returns:
the account
See Also:
getUsername()

getHostname

public java.lang.String getHostname()
Gets hostname of FTP server.

Returns:
hostname

getInputStream

public java.io.InputStream getInputStream(java.lang.String remoteFile,
                                          long pos)
                                   throws FtpException
Gets an InputStream from FTP server for the purposes of downloading a file.

Parameters:
remoteFile - remote file name to download
pos - file offset
Returns:
an InputStream
Throws:
FtpException - if an I/O or FTP error occurs.

setLinger

public void setLinger(int linger)
Sets the linger time for closing data sockets.

Parameters:
linger - the linger value in milliseconds

getLinger

public int getLinger()
Gets the linger time for closing data sockets.

Returns:
the linger time in milliseconds

setLocalDir

public void setLocalDir(java.io.File localDirectory)
Sets local directory to be used in FTP session. Downloads will be stored relative to local directory. Uploads are performed relative to current local directory.

Parameters:
localDirectory - the local directory

getLocalDir

public java.io.File getLocalDir()
Gets local directory to be used in FTP session. Downloads will be stored relative to local directory. Uploads are performed relative to current local directory.

Returns:
the local directory

getLocalDirListing

public java.util.Enumeration getLocalDirListing()
Gets local directory listing.

Returns:
an Enumeration of File

getMachineDirListing

public java.util.Enumeration getMachineDirListing(java.lang.String dirname)
                                           throws FtpException
Gets file listing of specified directory using MLSD command. This command is not supported by all FTP servers.

Parameters:
dirname - directory name or empty String for current directory
Returns:
an Enumeration of FtpFile
Throws:
FtpException - if an I/O or FTP error occurs
See Also:
FtpFile

getMachineDirListing

public java.util.Enumeration getMachineDirListing(java.lang.String dirname,
                                                  java.lang.String regex)
                                           throws FtpException
Gets file listing of specified directory using MLSD command. This command is not supported by all FTP servers.

Parameters:
dirname - directory name or empty String for current directory
regex - a regular expression e.g. ".*\\.txt" for all files ending in .txt extension
Returns:
an Enumeration of FtpFile
Throws:
FtpException - if an I/O or FTP error occurs

getMachineFileListing

public FtpFile getMachineFileListing(java.lang.String filename)
                              throws FtpException
Gets the file description for the specified filename using MLST command. This command is not supported by all FTP servers.

Parameters:
filename - target filename or empty for current directory
Returns:
an FtpFile
Throws:
FtpException - if an I/O or FTP error occurs
See Also:
FtpFile

getMode

public int getMode()
Gets data transfer mode for current session. Default mode is Ftp.AUTO where 0 = Ftp.AUTO, 1 = Ftp.ASCII, 2 = Ftp.BINARY

Returns:
the data transfer mode
See Also:
AUTO, BINARY, ASCII

getNameListing

public java.util.Enumeration getNameListing(java.lang.String filter)
                                     throws FtpException
Gets directory listing of files on FTP server matching filter criteria and using NLST command. Server is responsible for parsing filter.

Parameters:
filter - the filename filter
Returns:
an Enumeration of String where each item represents a file or directory name
Throws:
FtpException - if an I/O or FTP related error occurs

getNameListing

public java.util.Enumeration getNameListing()
                                     throws FtpException
Gets directory listing of files on FTP server.

Returns:
an Enumeration of String where each item represents a file or directory name
Throws:
FtpException - if an I/O or FTP related error occurs

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String fileName,
                                            long off,
                                            boolean append)
                                     throws FtpException
Gets an OutputStream from FTP server for the purposes of uploading a file.

Parameters:
fileName - the remote filename to store file as
off - file offset
append - true to append to remote file on FTP server, false otherwise
Returns:
an OutputStream
Throws:
FtpException - if an FTP error occurs.

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 Ftp server support this feature (MODE Z command)

Returns:
true data will be compressed, false otherwise.

setNATAddress

public void setNATAddress(java.lang.String ipAddress)
                   throws FtpException
Sets a NAT address which will be used for PASV file transfers. For active (non-passive) file transfer see the setPortAddress and setDataPortRange methods.

Parameters:
ipAddress - The NAT IP address.
Throws:
FtpException - if an I/O or FTP error occurs
See Also:
setDataPortRange(int, int), setPortAddress(String)

getNATAddress

public java.lang.String getNATAddress()
Get the NAT address.

Returns:
address

setPassive

public void setPassive(boolean passive)
Sets whether passive mode should be used. Default is true.

Parameters:
passive - true to use passive transfer, false otherwise

getPassive

public boolean getPassive()
Gets whether passive mode should be used. Default is true.

Returns:
true if passive mode is enabled, false otherwise

setPassword

public void setPassword(java.lang.String password)
Sets password of FTP user.

Parameters:
password - the password of FTP user

getPassword

public java.lang.String getPassword()
Returns current FTP user password.

Returns:
current FTP password.

setPort

public void setPort(int port)
Sets port of FTP server. Default value is 21.

Parameters:
port - the port of FTP server

getPort

public int getPort()
Gets port of FTP server. Default value is 21.

Returns:
port

setPortAddress

public void setPortAddress(java.lang.String string)
Sets the external IP address to use when listing for active connections using the PORT command.

Parameters:
string - an IP address

getPortAddress

public java.lang.String getPortAddress()
Gets the external IP address to use when listing for active connections using the PORT command.

Returns:
the external IP address

getResponseCode

public int getResponseCode()
Gets response code from last FTP command.

Returns:
response code or -1 if code cannot be determined

getSystemType

public java.lang.String getSystemType()
                               throws FtpException
Gets the system type of remote FTP server.

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

setSendBufferSize

public void setSendBufferSize(int sendBufferSize)
Sets the send buffer size option of the ftp connection.

Parameters:
sendBufferSize - Send buffer size.

setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)
Sets the receive buffer size option of the ftp connection.

Parameters:
receiveBufferSize - Receive buffer size.

setTimeout

public void setTimeout(int timeout)
Sets the timeout for opening connection to FTP server.

Parameters:
timeout - the timeout in milliseconds

getTimeout

public int getTimeout()
Gets the timeout for opening connection to FTP server.

Returns:
timeout in milliseconds

setKeepAlive

public void setKeepAlive(boolean keepAlive)
Set socket keep alive.

Parameters:
keepAlive -

getKeepAlive

public boolean getKeepAlive(boolean keepAlive)
Get socket keep alive.

Parameters:
keepAlive -
Returns:
keep alive

setUsername

public void setUsername(java.lang.String user)
Sets username of FTP user.

Parameters:
user - the username of FTP user

setUseEPSV

public void setUseEPSV(boolean useEPSV)
Sets whether to use EPSV or PASV command for data tranfers. Default is to use PASV command.

Parameters:
useEPSV - true to use EPSV command, false to use PASV command.

getUseEPRT

public boolean getUseEPRT()
Gets whether to use EPRT or PORT command for data tranfers.

Returns:
true to use EPRT command, false to use PORT command.

setUseEPRT

public void setUseEPRT(boolean useEPRT)
Sets whether to use EPRT or PASV command for data tranfers. Default is to use PASV command.

Parameters:
useEPSV - true to use EPRT command, false to use PORT command.

getUseEPSV

public boolean getUseEPSV()
Gets whether to use EPSV or PASV command for data tranfers.

Returns:
true to use EPSV command, false to use PASV command.

getUsername

public java.lang.String getUsername()
Gets username of FTP user.

Returns:
username

setWireEncoding

public void setWireEncoding(java.lang.String encoding)
Sets encoding set used when issuing commands and transferring files. Default is UTF8.

Parameters:
encoding - the character encoding to be used

getWireEncoding

public java.lang.String getWireEncoding()
Gets encoding set used when issuing commands and transferring files. Default is UTF8.

Returns:
the character encoding being used

addFtpListener

public void addFtpListener(FtpListener listener)
Adds FTP event listener.

Parameters:
listener - the listener to add
See Also:
FtpListener

changePassword

public void changePassword(java.lang.String oldPassword,
                           java.lang.String newPassword)
                    throws FtpException
Changes password for current account. This feature is not supported by RFC-959 so may not work on all FTP servers.

Parameters:
oldPassword - The old password.
newPassword - The new password.
Throws:
FtpException - FtpException if underlayed I/O or FTP error occurs.

checksum

public boolean checksum(java.io.File localfile,
                        java.lang.String remoteFile)
                 throws FtpException
Compares checksum of the local and remote files.

Parameters:
localfile - local file
remoteFile - remote file
Returns:
true if checksums are equal, false otherwise
Throws:
FtpException - if an error occurs

checksum

public boolean checksum(byte[] data,
                        java.lang.String remoteFile)
                 throws FtpException
Compares checksum of the local data and remote file.

Parameters:
data - data
remoteFile - remote file
Returns:
true if checksum are equal, false otherwise
Throws:
FtpException - if an error occurs

connect

public void connect()
             throws FtpException
Connects to FTP server and performs login using specified username, password and optional account.

Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setUsername(java.lang.String), setPassword(java.lang.String), setAccount(java.lang.String)

connect

public void connect(boolean login)
             throws FtpException
Connects to FTP server and optionally performs login.

Parameters:
login - true to login false otherwise
Throws:
FtpException - if an I/O or FTP error occurs

deleteDir

public void deleteDir(java.lang.String remoteDirectory,
                      boolean recurse)
               throws FtpException
Deletes directory from FTP server. If the directory cannot be deleted because it is not empty the recurse parameter will be used to determine if files and subdirectories within directory should be removed.

Parameters:
remoteDirectory - the directory to remove
recurse - true if it should delete files and subdirectories within directory
Throws:
FtpException - if an I/O or FTP error occurs.

deleteDir

public void deleteDir(java.lang.String remoteDirectory)
               throws FtpException
Deletes directory from FTP server.

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

deleteFile

public void deleteFile(java.lang.String remoteFile)
                throws FtpException
Deletes remote file from FTP server.

Parameters:
remoteFile - name of file to delete
Throws:
FtpException - if an I/O or FTP error occurs.

disconnect

public void disconnect()
Quits FTP session and disconnects from FTP server.


download

public void download(java.io.OutputStream out,
                     java.lang.String remoteFile)
              throws FtpException
Downloads file from FTP server and writes contents to provided OutputStream. Closure of OutputStream is responsibility of programmer.

Parameters:
out - the OutputStream to write download to
remoteFile - remote filename
Throws:
FtpException - if an I/O or FTP error occurs

download

public java.io.File download(java.lang.String localFile,
                             java.lang.String remoteFile)
                      throws FtpException
Downloads file from FTP server. Downloads are stored relative to current local directory.

Parameters:
localFile - destination filename relative to current local directory, NOT an absolute path
remoteFile - remote filename
Returns:
the file downloaded
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

download

public java.io.File download(java.lang.String remoteFile)
                      throws FtpException
Downloads file from FTP server. Downloads are stored relative to current local directory.

Parameters:
remoteFile - the file to download
Returns:
the file downloaded
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

downloadDir

public void downloadDir(java.lang.String remoteDir)
                 throws FtpException
Downloads remote directory and contents recursively from FTP server. Downloads are stored relative to current local directory.

Parameters:
remoteDir - the directory to download
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        boolean performChecksum)
                 throws FtpException
Downloads remote directory and contents from FTP server. Downloads are stored relative to current local directory.

Parameters:
remoteDir - the directory to download
retryLimit - retry limit if an error occurs
retryInterval - retry interval in seconds
performChecksum - whether to perform checksum after each download, not supported by all FTP servers
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        boolean performChecksum,
                        int threadCount)
                 throws FtpException
Download directory.

Parameters:
remoteDir -
retryLimit -
performChecksum -
threadCount -
Throws:
FtpException

downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        int retryInterval,
                        boolean performChecksum,
                        int threadCount)
                 throws FtpException
Downloads remote directory and contents from FTP server. Downloads are stored relative to current local directory.

Parameters:
remoteDir - the directory to download
retryLimit - retry limit if an error occurs
performChecksum - whether to perform checksum after each download, not supported by all FTP servers
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

abortDownloadThreads

public void abortDownloadThreads()
Abort all download threads.


downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        int retryInterval,
                        boolean performChecksum)
                 throws FtpException
Downloads remote directory and contents from FTP server. Downloads are stored relative to current local directory.

Parameters:
remoteDir - the directory to download
retryLimit - retry limit if an error occurs
performChecksum - whether to perform checksum after each download, not supported by all FTP servers
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

interrupt

public void interrupt()
Interrupts the current data transfer and sets interrupted flag to true. After invoking this method you must reset the interrupted flag to false before transferring any files.

See Also:
reset()

interrupted

public boolean interrupted()
Checks if transfer process was interrupted.

Returns:
true if transfer process was interrupted.

issueCommand

public java.lang.String issueCommand(java.lang.String cmd)
                              throws FtpException
Issues command to FTP server.

Parameters:
cmd - the command to issue
Returns:
response code
Throws:
FtpException - if an I/O or FTP error occurs

issueCommandCheck

public java.lang.String issueCommandCheck(java.lang.String cmd)
                                   throws FtpException
Issues command to FTP server.

Parameters:
cmd - the command to issue
Returns:
response code
Throws:
FtpException - if an I/O or FTP error occurs

login

public void login()
           throws FtpException
Logs into FTP server after establishing a connection. This method should only be used if login is not performed automatically during Ftp#connect.

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

makeDir

public void makeDir(java.lang.String newDirectory)
             throws FtpException
Makes directory on FTP server.

Parameters:
newDirectory - name of directory to make
Throws:
FtpException - if an I/O or FTP error occurs.

makeDirRecursive

public void makeDirRecursive(java.lang.String newDirectory)
                      throws FtpException
Makes directory on FTP server, creating subdirectories if necessary.

Parameters:
newDirectory - full path of directory to make
Throws:
FtpException - if an I/O or FTP error occurs

makeLocalDir

public java.io.File makeLocalDir(java.lang.String directoryName)
Creates local directory. Directory is relative to current local directory.

Parameters:
directoryName - name of directory
Returns:
the directory
See Also:
getLocalDir()

mdelete

public void mdelete(java.lang.String filter)
             throws FtpException
Deletes multiple files matching regular expression in FTP server's current directory. For example, to delete all files ending in .txt extension use regular expression ".*\\.txt"

Parameters:
filter - the filter to use
Throws:
FtpException - if an I/O or FTP error occurs.

mdownload

public void mdownload(java.util.Enumeration fileNames)
               throws FtpException
Downloads specified files in current working remote directory from FTP server to local directory. Do not use this method to download a directory, see downloadDir(String) method. Downloads are stored relative to current local directory.

Parameters:
fileNames - filenames of files to download
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File), downloadDir(String)

mdownload

public void mdownload(java.lang.String filter)
               throws FtpException
Downloads multiple files matching regular expression from FTP server current directory. Downloads are stored relative to current local directory. For example to download all files ending with extension .txt use the regular expression ".*\\.txt". To download a directory use the downloadDir method.

Parameters:
filter - the regular expression filter to use
Throws:
FtpException - if an I/O or FTP error occurs
See Also:
setLocalDir(java.io.File), downloadDir(java.lang.String)

mupload

public void mupload(java.util.Enumeration fileNames)
             throws FtpException
Uploads multiple files to FTP server. Uploads are performed relative to current local directory.

Parameters:
fileNames - an Enumeration of String filenames relative to current local directory to upload
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

mupload

public void mupload(java.lang.String filter)
             throws FtpException
Uploads multiple files matching regular expression to FTP server's current directory. Uploads are performed relative to current local directory. For example, to upload files ending in extension .txt use the regular expression ".*\\.txt".

Parameters:
filter - the filter to use
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

noop

public java.lang.String noop()
                      throws FtpException
Sends a NOOP (No Operation) command to FTP server. This is useful in helping to prevent a lost connection due to inactivity.

Returns:
the response to the NOOP command
Throws:
FtpException - if an I/O or FTP error occurs

readResponse

public void readResponse()
                  throws FtpException
Reads server response. Normally this method should not be invoked as this is done automatically. This should be used only in cases where manual reading of response is necessary.

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

removeFtpListener

public void removeFtpListener(FtpListener listener)
Removes specified FTP event listener.

Parameters:
listener - the listener to remove
See Also:
FtpListener

renameFile

public void renameFile(java.lang.String remoteFile,
                       java.lang.String newFile)
                throws FtpException
Renames remote file on FTP server.

Parameters:
remoteFile - name of file to rename
newFile - new name of file
Throws:
FtpException - if an I/O or FTP error occurs.

reset

public void reset()
Resets the interrupted flag to false. This method should be invoked if you have interrupted a transfer using the Ftp#interrupt method and wish to resume transfering files.

See Also:
interrupt()

resumeDownload

public java.io.File resumeDownload(java.lang.String remoteFile,
                                   long off)
                            throws FtpException
Resumes download of file from FTP server.

Parameters:
remoteFile - the file to download
off - file offset in bytes
Returns:
File the file downloaded
Throws:
FtpException - if an I/O or FTP error occurs.

resumeDownload

public java.io.File resumeDownload(java.lang.String localFile,
                                   java.lang.String remoteFile,
                                   long off)
                            throws FtpException
Resumes download of file from FTP server.

Parameters:
localFile - local file name
remoteFile - the file to download
off - file offset in bytes
Returns:
File the file downloaded
Throws:
FtpException - if an I/O or FTP error occurs.

resumeUpload

public void resumeUpload(java.io.File localFile,
                         long off)
                  throws FtpException
Resumes upload of file to FTP server.

Parameters:
localFile - the local file to upload
off - file offset in bytes
Throws:
FtpException - if an I/O or FTP error occurs.

resumeUpload

public void resumeUpload(java.io.File localFile,
                         java.lang.String remoteFile,
                         long off)
                  throws FtpException
Resumes upload of file to FTP server.

Parameters:
localFile - the local file to upload
remoteFile - the destination file on FTP server
off - local file offset in bytes
Throws:
FtpException - if an I/O or FTP error occurs

resumeUpload

public void resumeUpload(java.lang.String localFile,
                         long off)
                  throws FtpException
Resumes upload of file to FTP server.

Parameters:
localFile - the local file to upload
off - file offset in bytes
Throws:
FtpException - if an I/O or FTP error occurs.

resumeUpload

public void resumeUpload(java.lang.String localFile,
                         java.lang.String remoteFile,
                         long off)
                  throws FtpException
Resumes upload of file to FTP server.

Parameters:
localFile - the local file to upload
remoteFile - the destination file on FTP server
off - the local file offset
Throws:
FtpException - if an I/O or FTP related error occurs.

upload

public void upload(java.io.File localFile,
                   java.lang.String remoteFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server. If localFile is a directory then directory and entire contents are uploaded.

Parameters:
localFile - the local file to upload
remoteFile - the destination of upload
append - true to append to remote file on FTP server, false otherwise
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.io.InputStream input,
                   java.lang.String remoteFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server.

Parameters:
input - the InputStream to read from
remoteFile - the destination filename of upload
append - true to append, false otherwise
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.io.InputStream input,
                   java.lang.String remoteFile)
            throws FtpException
Uploads file to FTP server.

Parameters:
input - the InputStream to read from
remoteFile - the destination filename of upload
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.io.File localFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server. If localFile is a directory then directory and entire contents are uploaded.

Parameters:
localFile - the local file to upload
append - true to append to remote file on FTP server, false otherwise
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.io.File localFile,
                   java.lang.String remoteFile)
            throws FtpException
Uploads file to FTP server. If localFile is a directory then directory and entire contents are uploaded.

Parameters:
localFile - the local file to upload
remoteFile - the destination of upload
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.io.File localFile)
            throws FtpException
Uploads file to FTP server. If localFile is a directory then directory and entire contents are uploaded.

Parameters:
localFile - the local file to upload
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.lang.String extension,
                   java.io.File localFile)
            throws FtpException
Uploads file to FTP server and renames the remote file name.

Parameters:
extension - the temporary extension to append to file before renaming
localFile - the local file to upload
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(java.lang.String localFile,
                   java.lang.String remoteFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server. Uploads are performed relative to current local directory.

Parameters:
localFile - the local file to upload
remoteFile - the destination filename of upload
append - true to append to remote file on FTP server, false otherwise
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

upload

public void upload(java.lang.String localFile,
                   java.lang.String remoteFile)
            throws FtpException
Uploads file to FTP server. Uploads are performed relative to current local directory.

Parameters:
localFile - the local file to upload
remoteFile - the destination filename of upload
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

upload

public void upload(java.lang.String localFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server. Uploads are performed relative to current local directory.

Parameters:
localFile - the local file to upload
append - true to append to remote file on FTP server, false otherwise
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

upload

public void upload(java.lang.String localFile)
            throws FtpException
Uploads file to FTP server. Uploads are performed relative to current local directory.

Parameters:
localFile - the local file to upload
Throws:
FtpException - if an I/O or FTP error occurs.
See Also:
setLocalDir(java.io.File)

upload

public void upload(byte[] data,
                   java.lang.String remoteFile,
                   boolean append)
            throws FtpException
Uploads file to FTP server where contents of file is not on disk but in memory.

Parameters:
data - the raw contents of the file to upload
remoteFile - the filename to store file as on FTP server
append - true to append to remote file on FTP server, false otherwise
Throws:
FtpException - if an I/O or FTP related error occurs

upload

public void upload(byte[] data,
                   java.lang.String remoteFile)
            throws FtpException
Uploads file to FTP server where contents of file is not on disk but in memory.

Parameters:
data - the raw contents of the file to upload
remoteFile - the filename to store file as on FTP server
Throws:
FtpException - if an I/O or FTP related error occurs

uploadDir

public void uploadDir(java.io.File localDir)
               throws FtpException
Uploads local directory and contents recursively to FTP server. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
Throws:
FtpException - if an I/O or FTP error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      java.lang.String extension)
               throws FtpException
Uploads local directory and contents recursively to FTP server. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
extension - the temporary extension to use before renaming file or null to use default extension
Throws:
FtpException - if an I/O or FTP error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      boolean performChecksum)
               throws FtpException
Uploads local directory and contents to FTP server. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
retryLimit - the retry limit if upload fails
performChecksum - whether to perform checksum after each file upload, not supported by all FTP servers
Throws:
FtpException - if an I/O or FTP error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      int retryInterval,
                      boolean performChecksum,
                      java.lang.String extension)
               throws FtpException
Uploads local directory and contents to FTP server. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
retryLimit - the retry limit if upload fails
performChecksum - whether to perform checksum after each upload, not supported by all FTP servers
extension - the temporary extension to use before renaming files or null to use default extension
Throws:
FtpException - if an I/O or FTP error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      boolean performChecksum,
                      java.lang.String extension,
                      int threadCount)
               throws FtpException
Throws:
FtpException

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      int retryInterval,
                      boolean performChecksum,
                      java.lang.String extension,
                      int threadCount)
               throws FtpException
Uploads local directory and contents to FTP server. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
retryLimit - the retry limit if upload fails
performChecksum - whether to perform checksum after each upload, not supported by all FTP servers
extension - the temporary extension to use before renaming files or null to use default extension
threadCount - the number of threads to use for transferring files
Throws:
FtpException - if an I/O or FTP error occurs.

abortUploadThreads

public void abortUploadThreads()
Cancel all upload threads.


uploadUnique

public java.lang.String uploadUnique(java.lang.String fileName)
                              throws FtpException
Uploads file to FTP server storing remotely using a unique name.

Parameters:
fileName - the filename to upload, filename will be used as seed for unique remote filename
Returns:
the unique filename
Throws:
FtpException - if an I/O or FTP related error occurs

uploadUnique

public java.lang.String uploadUnique(java.lang.String fileName,
                                     boolean useFilenameAsSeed)
                              throws FtpException
Uploads file to FTP server storing remotely using a unique name.

Parameters:
fileName - the filename to upload, filename will be used as seed for unique remote filename
useFilenameAsSeed - whether filename should be used as seed value for generating unique filename on server
Returns:
the unique filename
Throws:
FtpException - if an I/O or FTP related error occurs

uploadUnique

public java.lang.String uploadUnique(java.io.File file)
                              throws FtpException
Uploads file to FTP server storing remotely using a unique name.

Parameters:
file - the file to upload, filename will be used as seed for unique remote filename
Returns:
the unique file name
Throws:
FtpException - if an I/O or FTP related error occurs

uploadUnique

public java.lang.String uploadUnique(java.io.File file,
                                     boolean useFilenameAsSeed)
                              throws FtpException
Uploads file to FTP server storing remotely using a unique name.

Parameters:
file - the file to upload, filename will be used as seed for unique remote filename
useFilenameAsSeed - whether filename should be used as seed value for generating unique filename on server
Returns:
the unique file name
Throws:
FtpException - if an I/O or FTP related error occurs

uploadUnique

public java.lang.String uploadUnique(java.io.InputStream in,
                                     java.lang.String fileName)
                              throws FtpException
Uploads file to FTP server storing remotely using a unique name.

Parameters:
in - the data InputStream to upload from
fileName - the filename to be used as seed for unique remote filename
Returns:
the unique file name
Throws:
FtpException - if an I/O or FTP related error occurs

getRecursiveDirectoryFileCount

public int getRecursiveDirectoryFileCount(java.lang.String directory)
Get size of all files rescursively in a given remote directory.

Parameters:
directory - - the remote directory name
Returns:
size of files.

getRecursiveDirectorySize

public long getRecursiveDirectorySize(java.lang.String directory)
Get size of all files rescursively in a given remote directory.

Parameters:
directory - - the remote directory name
Returns:
size of files.

getRemoteFileList

public java.util.Vector getRemoteFileList(java.lang.String remoteDir)
                                   throws FtpException
Gets a remote file list fron the current directory.

Parameters:
remoteDir - The current remote directory
Returns:
A collection of file paths.
Throws:
FtpException - If a Ftp error occurs

getLocalChecksum

public java.lang.String getLocalChecksum(java.io.File localFile)
                                  throws FtpException
Returns local checksum.

Parameters:
localFile - the file to use in calculating checksum
Returns:
local file checksum
Throws:
FtpException - if an error occurs

getRemoteFileChecksum

public java.lang.String getRemoteFileChecksum(java.lang.String remoteFile)
                                       throws FtpException
Returns remote file checksum.

Parameters:
remoteFile - remote file
Returns:
remote file checksum.
Throws:
FtpException - if an error occurs

Secure FTP Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved