public abstract class ApacheFtpClientImpl<T extends org.apache.commons.net.ftp.FTPClient> extends FileTransferClientImp implements FtpFileTransferClient
FileTransferClient
that uses the apache
commons net FTP implementation.Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
additionalSettings |
logR
Constructor and Description |
---|
ApacheFtpClientImpl(java.lang.String remoteHost,
int port,
int timeout)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
chdir(java.lang.String dir)
change directory on the server
|
void |
connect(java.lang.String user,
java.lang.String password)
Connect and login into an account on the FTP server.
|
void |
connect(java.lang.String user,
java.lang.String password,
java.lang.String account)
Connect and login into an account on the FTP server.
|
protected abstract T |
createFTPClient()
Create the base commons net client.
|
void |
delete(java.lang.String remoteFile)
delete a file on the server
|
java.lang.String[] |
dir(java.lang.String dirname,
boolean full)
List a directory's contents as an array of strings.
|
java.lang.String[] |
dir(java.lang.String directory,
java.io.FileFilter filter)
List a directory's contents
|
void |
disconnect()
disconnect from the server
|
protected static <T extends org.apache.commons.net.ftp.FTPClient> |
disconnect(T ftp) |
void |
get(java.io.OutputStream destStream,
java.lang.String remoteFile)
Get data from a remote file
|
byte[] |
get(java.lang.String remoteFile)
Get data as a byte array from a server file
|
long |
getKeepAliveTimeout()
Get the time to wait between sending control connection keepalive messages.
|
int |
getTimeout() |
protected void |
handleReturnValue(boolean value) |
boolean |
isConnected()
Check if this client is still connected to its target
Any errors return a false
This is used to check cached connections are still working
|
long |
lastModified(java.lang.String path)
Get last modified date time of file
|
java.util.Date |
lastModifiedDate(java.lang.String path)
Get last modified date time of file
|
void |
mkdir(java.lang.String dir)
create a directory on the server
|
protected abstract void |
postConnectSettings(T client) |
protected abstract void |
preConnectSettings(T client) |
void |
put(java.io.InputStream srcStream,
java.lang.String remoteFile,
boolean append)
Put a stream of data onto the FTP server.
|
java.lang.String |
pwd()
Get the current working directory on the server
|
void |
rename(java.lang.String from,
java.lang.String to)
rename a file on the server
|
void |
rmdir(java.lang.String dir)
remove a directory from the server
|
void |
setDataMode(FtpDataMode mode) |
void |
setKeepAliveTimeout(long seconds)
Set the time to wait between sending control connection keepalive messages when processing file upload or download.
|
void |
setServerTimezone(java.util.TimeZone tz)
Set the FTP Server timezone handler for modification times.
|
void |
setTimeout(int millis) |
void |
setType(TransferType ftpFileType)
Set transfer type eg.
|
java.lang.String |
system()
Get the type of the OS at the server
|
<S extends ApacheFtpClientImpl> |
withAdditionalSettings(java.util.Map<java.lang.String,java.lang.String> settings) |
ensureNotNull, isAdditionaDebug, log, setAdditionalDebug
protected transient java.util.Map<java.lang.String,java.lang.String> additionalSettings
public ApacheFtpClientImpl(java.lang.String remoteHost, int port, int timeout) throws java.io.IOException
remoteHost
- the remote hostnameport
- connection porttimeout
- connection timeoutjava.io.IOException
public <S extends ApacheFtpClientImpl> S withAdditionalSettings(java.util.Map<java.lang.String,java.lang.String> settings)
protected abstract T createFTPClient()
protected abstract void preConnectSettings(T client) throws java.io.IOException
java.io.IOException
protected abstract void postConnectSettings(T client) throws java.io.IOException
java.io.IOException
public int getTimeout() throws java.io.IOException
java.io.IOException
public void setTimeout(int millis)
public void connect(java.lang.String user, java.lang.String password) throws java.io.IOException
FileTransferClient
connect
in interface FileTransferClient
user
- user namepassword
- user's passwordFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void connect(java.lang.String user, java.lang.String password, java.lang.String account) throws java.io.IOException
FtpFileTransferClient
connect
in interface FtpFileTransferClient
user
- user namepassword
- user's passwordaccount
- the accountFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void put(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append) throws java.io.IOException
FileTransferClient
put
in interface FileTransferClient
srcStream
- input stream of data to putremoteFile
- name of remote fileappend
- true if appending, false otherwiseFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void get(java.io.OutputStream destStream, java.lang.String remoteFile) throws java.io.IOException
get
in interface FileTransferClient
destStream
- output target data streamremoteFile
- file to be read on the serverFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic byte[] get(java.lang.String remoteFile) throws java.io.IOException
get
in interface FileTransferClient
remoteFile
- file to be read on the serverFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic java.lang.String[] dir(java.lang.String directory, java.io.FileFilter filter) throws FileTransferException, java.io.IOException
FileTransferClient
Note that although we use a standard FileFilter
interface here operating on
File
; it actually uses RemoteFile
instead which overrides information
that can be obtained from the remote server. Other standard File
operations will
not be supported, and may ultimately cause a runtime exception.
dir
in interface FileTransferClient
directory
- the directory to list.filter
- the filefilter mask to useFileTransferException
- on FTP Specific exception error.java.io.IOException
- on comms error.public java.lang.String[] dir(java.lang.String dirname, boolean full) throws java.io.IOException
FileTransferClient
A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server. Note that a full listing can be used on a file name to obtain information about a file. The special files "." and ".." are ignored.
dir
in interface FileTransferClient
dirname
- name of directory (not a file mask)full
- true if detailed listing required false otherwiseFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void delete(java.lang.String remoteFile) throws java.io.IOException
delete
in interface FileTransferClient
remoteFile
- to be deletedFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void rename(java.lang.String from, java.lang.String to) throws java.io.IOException
rename
in interface FileTransferClient
from
- file to be renamedto
- new name for fileFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void rmdir(java.lang.String dir) throws java.io.IOException
rmdir
in interface FileTransferClient
dir
- directory nameFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void mkdir(java.lang.String dir) throws java.io.IOException
mkdir
in interface FileTransferClient
dir
- directory nameFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void chdir(java.lang.String dir) throws java.io.IOException
chdir
in interface FileTransferClient
dir
- directory nameFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void disconnect() throws java.io.IOException
disconnect
in interface FileTransferClient
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void setType(TransferType ftpFileType) throws java.io.IOException
ftpFileType
- FILE_TYPE constant from the Apache commons net FtpClient
classjava.io.IOException
public long lastModified(java.lang.String path) throws java.io.IOException
lastModified
in interface FileTransferClient
path
- the path to the filename.FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic java.util.Date lastModifiedDate(java.lang.String path) throws java.io.IOException
lastModifiedDate
in interface FileTransferClient
path
- the path to the filename.FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void setServerTimezone(java.util.TimeZone tz)
tz
- the handler.public java.lang.String system() throws java.io.IOException
java.io.IOException
- if a comms error occurspublic java.lang.String pwd() throws java.io.IOException
java.io.IOException
- if a comms error occurspublic void setDataMode(FtpDataMode mode) throws java.io.IOException
java.io.IOException
public long getKeepAliveTimeout() throws FileTransferException
FileTransferClient
getKeepAliveTimeout
in interface FileTransferClient
FileTransferException
public void setKeepAliveTimeout(long seconds) throws FileTransferException
FileTransferClient
setKeepAliveTimeout
in interface FileTransferClient
seconds
- time in secondsFileTransferException
public boolean isConnected()
FileTransferClient
isConnected
in interface FileTransferClient
protected void handleReturnValue(boolean value) throws java.io.IOException
java.io.IOException
protected static <T extends org.apache.commons.net.ftp.FTPClient> T disconnect(T ftp) throws java.io.IOException
java.io.IOException