Class FTPClientWrapper
- java.lang.Object
-
- org.apache.commons.vfs2.provider.ftp.FTPClientWrapper
-
- All Implemented Interfaces:
FtpClient
public class FTPClientWrapper extends java.lang.Object implements FtpClient
A wrapper to the FTPClient to allow automatic reconnect on connection loss.I decided to not to use eg. noop() to determine the state of the connection to avoid unnecessary server round-trips.
-
-
Field Summary
Fields Modifier and Type Field Description protected FileSystemOptions
fileSystemOptions
Authentication options.
-
Constructor Summary
Constructors Modifier Constructor Description protected
FTPClientWrapper(GenericFileName rootFileName, FileSystemOptions fileSystemOptions)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
abort()
Aborts the current operation.java.io.OutputStream
appendFileStream(java.lang.String relPath)
Returns an OutputStream through which data can be written to append to a file on the server with the given name.boolean
completePendingCommand()
There are a few FTPClient methods that do not complete the entire sequence of FTP commands to complete a transaction.protected org.apache.commons.net.ftp.FTPClient
createClient(GenericFileName rootFileName, UserAuthenticationData authData)
Creates an FTPClient.boolean
deleteFile(java.lang.String relPath)
Deletes a file on the FTP server.void
disconnect()
Sends the FTP QUIT command to the server, receive the reply, and return the reply code.FileSystemOptions
getFileSystemOptions()
Gets the FileSystemOptions.int
getReplyCode()
Gets the integer value of the reply code of the last FTP reply.java.lang.String
getReplyString()
Gets the entire text of the last FTP server response exactly as it was received, including all end of line markers in NETASCII format.GenericFileName
getRoot()
Gets the root file name.boolean
hasFeature(java.lang.String feature)
Queries the server for a supported feature.boolean
isConnected()
Tests if the client is currently connected to a server.org.apache.commons.net.ftp.FTPFile[]
listFiles(java.lang.String relPath)
Using the default system autodetect mechanism, obtain a list of file information for the current working directory or for just a single file.boolean
makeDirectory(java.lang.String relPath)
Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is given).java.time.Instant
mdtmInstant(java.lang.String relPath)
Sends the MDTM command to get a file's date and time information after file transfer.boolean
removeDirectory(java.lang.String relPath)
Removes a directory on the FTP server (if empty).boolean
rename(java.lang.String oldName, java.lang.String newName)
Renames a remote file.java.io.InputStream
retrieveFileStream(java.lang.String relPath)
Returns an InputStream from which a named file from the server can be read.java.io.InputStream
retrieveFileStream(java.lang.String relPath, int bufferSize)
Returns an InputStream from which a named file from the server can be read.java.io.InputStream
retrieveFileStream(java.lang.String relPath, long restartOffset)
Returns an InputStream from which a named file from the server can be read.void
setBufferSize(int bufferSize)
Sets the buffer size for buffered data streams.java.io.OutputStream
storeFileStream(java.lang.String relPath)
Returns an OutputStream through which data can be written to store a file on the server using the given name.
-
-
-
Field Detail
-
fileSystemOptions
protected final FileSystemOptions fileSystemOptions
Authentication options.
-
-
Constructor Detail
-
FTPClientWrapper
protected FTPClientWrapper(GenericFileName rootFileName, FileSystemOptions fileSystemOptions) throws FileSystemException
Constructs a new instance.- Parameters:
rootFileName
- the root file name.fileSystemOptions
- the file system options.- Throws:
FileSystemException
- if a file system error occurs.
-
-
Method Detail
-
abort
public boolean abort() throws java.io.IOException
Description copied from interface:FtpClient
Aborts the current operation.
-
appendFileStream
public java.io.OutputStream appendFileStream(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Returns an OutputStream through which data can be written to append to a file on the server with the given name.- Specified by:
appendFileStream
in interfaceFtpClient
- Parameters:
relPath
- The name of the remote file.- Returns:
- An OutputStream through which the remote file can be appended.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
completePendingCommand
public boolean completePendingCommand() throws java.io.IOException
Description copied from interface:FtpClient
There are a few FTPClient methods that do not complete the entire sequence of FTP commands to complete a transaction. These commands require some action by the programmer after the reception of a positive intermediate command. After the programmer's code completes its actions, it must call this method to receive the completion reply from the server and verify the success of the entire transaction.- Specified by:
completePendingCommand
in interfaceFtpClient
- Returns:
- true if successfully completed, false if not.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
createClient
protected org.apache.commons.net.ftp.FTPClient createClient(GenericFileName rootFileName, UserAuthenticationData authData) throws FileSystemException
Creates an FTPClient.- Parameters:
rootFileName
- the root file name.authData
- authentication data.- Returns:
- an FTPClient.
- Throws:
FileSystemException
- if a file system error occurs.
-
deleteFile
public boolean deleteFile(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Deletes a file on the FTP server.- Specified by:
deleteFile
in interfaceFtpClient
- Parameters:
relPath
- The relPath of the file to be deleted.- Returns:
- true if successfully completed, false if not.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
disconnect
public void disconnect() throws java.io.IOException
Description copied from interface:FtpClient
Sends the FTP QUIT command to the server, receive the reply, and return the reply code.- Specified by:
disconnect
in interfaceFtpClient
- Throws:
java.io.IOException
- If an I/O error occurs.
-
getFileSystemOptions
public FileSystemOptions getFileSystemOptions()
Gets the FileSystemOptions.- Returns:
- the FileSystemOptions.
-
getReplyCode
public int getReplyCode() throws java.io.IOException
Description copied from interface:FtpClient
Gets the integer value of the reply code of the last FTP reply.- Specified by:
getReplyCode
in interfaceFtpClient
- Returns:
- The integer value of the reply code of the last FTP reply.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
getReplyString
public java.lang.String getReplyString() throws java.io.IOException
Description copied from interface:FtpClient
Gets the entire text of the last FTP server response exactly as it was received, including all end of line markers in NETASCII format.- Specified by:
getReplyString
in interfaceFtpClient
- Returns:
- The entire text from the last FTP response as a String.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
getRoot
public GenericFileName getRoot()
Gets the root file name.- Returns:
- the root file name.
-
hasFeature
public boolean hasFeature(java.lang.String feature) throws java.io.IOException
Queries the server for a supported feature.- Specified by:
hasFeature
in interfaceFtpClient
- Parameters:
feature
- the name of the feature, converted to upper case.- Returns:
true
if the feature is present,false
if the feature is not present or the FTP command failed.- Throws:
java.io.IOException
- If an I/O error occurs.
-
isConnected
public boolean isConnected() throws FileSystemException
Description copied from interface:FtpClient
Tests if the client is currently connected to a server.- Specified by:
isConnected
in interfaceFtpClient
- Returns:
- true if the client is currently connected to a server, false otherwise.
- Throws:
FileSystemException
- If an I/O error occurs.
-
listFiles
public org.apache.commons.net.ftp.FTPFile[] listFiles(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Using the default system autodetect mechanism, obtain a list of file information for the current working directory or for just a single file.TODO This interface should not leak Apache Commons NET types like FTPFile
-
makeDirectory
public boolean makeDirectory(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is given).- Specified by:
makeDirectory
in interfaceFtpClient
- Parameters:
relPath
- The pathname of the directory to create.- Returns:
- true if successfully completed, false if not.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
mdtmInstant
public java.time.Instant mdtmInstant(java.lang.String relPath) throws java.io.IOException
Sends the MDTM command to get a file's date and time information after file transfer. It is typically more accurate than the"LIST"
command response. Time values are always represented in UTC (GMT), and in the Gregorian calendar regardless of what calendar may have been in use at the date and time the file was last modified.NOTE: not all remote FTP servers support
MDTM
.- Specified by:
mdtmInstant
in interfaceFtpClient
- Parameters:
relPath
- The relative path of the file object to executeMDTM
command against- Returns:
- new
Instant
object containing theMDTM
timestamp. - Throws:
java.io.IOException
- If an I/O error occurs.
-
removeDirectory
public boolean removeDirectory(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Removes a directory on the FTP server (if empty).- Specified by:
removeDirectory
in interfaceFtpClient
- Parameters:
relPath
- The pathname of the directory to remove.- Returns:
- true if successfully completed, false if not.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
rename
public boolean rename(java.lang.String oldName, java.lang.String newName) throws java.io.IOException
Description copied from interface:FtpClient
Renames a remote file.
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Returns an InputStream from which a named file from the server can be read.- Specified by:
retrieveFileStream
in interfaceFtpClient
- Parameters:
relPath
- The name of the remote file.- Returns:
- An InputStream from which the remote file can be read.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath, int bufferSize) throws java.io.IOException
Description copied from interface:FtpClient
Returns an InputStream from which a named file from the server can be read.- Specified by:
retrieveFileStream
in interfaceFtpClient
- Parameters:
relPath
- The name of the remote file.bufferSize
- buffer size.- Returns:
- An InputStream from which the remote file can be read.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath, long restartOffset) throws java.io.IOException
Description copied from interface:FtpClient
Returns an InputStream from which a named file from the server can be read.- Specified by:
retrieveFileStream
in interfaceFtpClient
- Parameters:
relPath
- The name of the remote file.restartOffset
- restart offset.- Returns:
- An InputStream from which the remote file can be read.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
setBufferSize
public void setBufferSize(int bufferSize) throws FileSystemException
Description copied from interface:FtpClient
Sets the buffer size for buffered data streams.- Specified by:
setBufferSize
in interfaceFtpClient
- Parameters:
bufferSize
- The size of the buffer.- Throws:
FileSystemException
- If an I/O error occurs.
-
storeFileStream
public java.io.OutputStream storeFileStream(java.lang.String relPath) throws java.io.IOException
Description copied from interface:FtpClient
Returns an OutputStream through which data can be written to store a file on the server using the given name.- Specified by:
storeFileStream
in interfaceFtpClient
- Parameters:
relPath
- The name to give the remote file.- Returns:
- An OutputStream through which the remote file can be written.
- Throws:
java.io.IOException
- If an I/O error occurs.
-
-