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
private org.apache.commons.net.ftp.FTPClient
ftpClient
private static org.apache.commons.logging.Log
LOG
private GenericFileName
root
-
Constructor Summary
Constructors Modifier Constructor Description protected
FTPClientWrapper(GenericFileName root, FileSystemOptions fileSystemOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
abort()
java.io.OutputStream
appendFileStream(java.lang.String relPath)
boolean
completePendingCommand()
private org.apache.commons.net.ftp.FTPClient
createClient()
protected org.apache.commons.net.ftp.FTPClient
createClient(GenericFileName rootName, UserAuthenticationData authData)
boolean
deleteFile(java.lang.String relPath)
void
disconnect()
FileSystemOptions
getFileSystemOptions()
private org.apache.commons.net.ftp.FTPClient
getFtpClient()
int
getReplyCode()
java.lang.String
getReplyString()
GenericFileName
getRoot()
boolean
hasFeature(java.lang.String feature)
Queries the server for a supported feature.boolean
isConnected()
org.apache.commons.net.ftp.FTPFile[]
listFiles(java.lang.String relPath)
private org.apache.commons.net.ftp.FTPFile[]
listFilesInDirectory(java.lang.String relPath)
boolean
makeDirectory(java.lang.String relPath)
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)
boolean
rename(java.lang.String oldName, java.lang.String newName)
java.io.InputStream
retrieveFileStream(java.lang.String relPath)
java.io.InputStream
retrieveFileStream(java.lang.String relPath, int bufferSize)
java.io.InputStream
retrieveFileStream(java.lang.String relPath, long restartOffset)
void
setBufferSize(int bufferSize)
java.io.OutputStream
storeFileStream(java.lang.String relPath)
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
fileSystemOptions
protected final FileSystemOptions fileSystemOptions
-
ftpClient
private org.apache.commons.net.ftp.FTPClient ftpClient
-
root
private final GenericFileName root
-
-
Constructor Detail
-
FTPClientWrapper
protected FTPClientWrapper(GenericFileName root, FileSystemOptions fileSystemOptions) throws FileSystemException
- Throws:
FileSystemException
-
-
Method Detail
-
abort
public boolean abort() throws java.io.IOException
-
appendFileStream
public java.io.OutputStream appendFileStream(java.lang.String relPath) throws java.io.IOException
- Specified by:
appendFileStream
in interfaceFtpClient
- Throws:
java.io.IOException
-
completePendingCommand
public boolean completePendingCommand() throws java.io.IOException
- Specified by:
completePendingCommand
in interfaceFtpClient
- Throws:
java.io.IOException
-
createClient
private org.apache.commons.net.ftp.FTPClient createClient() throws FileSystemException
- Throws:
FileSystemException
-
createClient
protected org.apache.commons.net.ftp.FTPClient createClient(GenericFileName rootName, UserAuthenticationData authData) throws FileSystemException
- Throws:
FileSystemException
-
deleteFile
public boolean deleteFile(java.lang.String relPath) throws java.io.IOException
- Specified by:
deleteFile
in interfaceFtpClient
- Throws:
java.io.IOException
-
disconnect
public void disconnect() throws java.io.IOException
- Specified by:
disconnect
in interfaceFtpClient
- Throws:
java.io.IOException
-
getFileSystemOptions
public FileSystemOptions getFileSystemOptions()
-
getFtpClient
private org.apache.commons.net.ftp.FTPClient getFtpClient() throws FileSystemException
- Throws:
FileSystemException
-
getReplyCode
public int getReplyCode() throws java.io.IOException
- Specified by:
getReplyCode
in interfaceFtpClient
- Throws:
java.io.IOException
-
getReplyString
public java.lang.String getReplyString() throws java.io.IOException
- Specified by:
getReplyString
in interfaceFtpClient
- Throws:
java.io.IOException
-
getRoot
public GenericFileName getRoot()
-
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
- on error
-
isConnected
public boolean isConnected() throws FileSystemException
- Specified by:
isConnected
in interfaceFtpClient
- Throws:
FileSystemException
-
listFiles
public org.apache.commons.net.ftp.FTPFile[] listFiles(java.lang.String relPath) throws java.io.IOException
-
listFilesInDirectory
private org.apache.commons.net.ftp.FTPFile[] listFilesInDirectory(java.lang.String relPath) throws java.io.IOException
- Throws:
java.io.IOException
-
makeDirectory
public boolean makeDirectory(java.lang.String relPath) throws java.io.IOException
- Specified by:
makeDirectory
in interfaceFtpClient
- Throws:
java.io.IOException
-
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 the underlying FTP client encountered an error.
-
removeDirectory
public boolean removeDirectory(java.lang.String relPath) throws java.io.IOException
- Specified by:
removeDirectory
in interfaceFtpClient
- Throws:
java.io.IOException
-
rename
public boolean rename(java.lang.String oldName, java.lang.String newName) throws java.io.IOException
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath) throws java.io.IOException
- Specified by:
retrieveFileStream
in interfaceFtpClient
- Throws:
java.io.IOException
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath, int bufferSize) throws java.io.IOException
- Specified by:
retrieveFileStream
in interfaceFtpClient
- Throws:
java.io.IOException
-
retrieveFileStream
public java.io.InputStream retrieveFileStream(java.lang.String relPath, long restartOffset) throws java.io.IOException
- Specified by:
retrieveFileStream
in interfaceFtpClient
- Throws:
java.io.IOException
-
setBufferSize
public void setBufferSize(int bufferSize) throws FileSystemException
- Specified by:
setBufferSize
in interfaceFtpClient
- Throws:
FileSystemException
-
storeFileStream
public java.io.OutputStream storeFileStream(java.lang.String relPath) throws java.io.IOException
- Specified by:
storeFileStream
in interfaceFtpClient
- Throws:
java.io.IOException
-
-