Package com.adaptris.filetransfer
Interface FileTransferClient
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Subinterfaces:
FtpFileTransferClient
- All Known Implementing Classes:
ApacheFtpClientImpl
,CommonsNetFtpClient
,CommonsNetFtpSslClient
,FileTransferClientImp
,SftpClient
public interface FileTransferClient extends java.io.Closeable
Common interface for all FTP client flavours.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
chdir(java.lang.String dir)
Change the remote working directory to that supplieddefault void
close()
void
connect(java.lang.String user, java.lang.String password)
Connect and login into an account on the FTP server.void
delete(java.lang.String remoteFile)
Delete the specified remote filedefault java.lang.String[]
dir()
List current directory's contents as an array of strings of filenames.default java.lang.String[]
dir(java.lang.String dirname)
List a directory's contents as an array of strings of filenames.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 contentsvoid
disconnect()
Quit the FTP sessionvoid
get(java.io.OutputStream destStream, java.lang.String remoteFile)
Get data from the FTP server.byte[]
get(java.lang.String remoteFile)
Get data from the FTP server.default void
get(java.lang.String localPath, java.lang.String remoteFile)
Get data from the FTP server.long
getKeepAliveTimeout()
Get the time to wait between sending control connection keepalive messages.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 workingboolean
isDirectory(java.lang.String path)
long
lastModified(java.lang.String path)
Return the last modified time for the given path.java.util.Date
lastModifiedDate(java.lang.String path)
Return the last modified date for the given path.void
mkdir(java.lang.String dir)
Create the specified remote working directorydefault void
put(byte[] bytes, java.lang.String remoteFile)
Put data onto the FTP server.default void
put(byte[] bytes, java.lang.String remoteFile, boolean append)
Put data onto the FTP server.default void
put(java.io.InputStream srcStream, java.lang.String remoteFile)
Put a stream of data onto the FTP server.void
put(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append)
Put a stream of data onto the FTP server.default void
put(java.lang.String localPath, java.lang.String remoteFile)
Put a local file onto the FTP server.default void
put(java.lang.String localPath, java.lang.String remoteFile, boolean append)
Put a local file onto the FTP server.void
rename(java.lang.String from, java.lang.String to)
Rename a file or directoryvoid
rmdir(java.lang.String dir)
Delete the specified remote working directoryvoid
setAdditionalDebug(boolean b)
Switch additional debug on or offvoid
setKeepAliveTimeout(long seconds)
Set the time to wait between sending control connection keepalive messages when processing file upload or download.
-
-
-
Method Detail
-
connect
void connect(java.lang.String user, java.lang.String password) throws java.io.IOException, FileTransferException
Connect and login into an account on the FTP server. This completes the entire login process- Parameters:
user
- user namepassword
- user's password- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
put
default void put(java.lang.String localPath, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Put a local file onto the FTP server.- Parameters:
remoteFile
- name of remote file in current directory- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
put(String, String, boolean)
withappend=false
.
-
put
default void put(java.io.InputStream srcStream, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Put a stream of data onto the FTP server.- Parameters:
srcStream
- input stream of data to putremoteFile
- name of remote file- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
put(String, String, boolean)
withappend=false
.
-
put
default void put(java.lang.String localPath, java.lang.String remoteFile, boolean append) throws java.io.IOException, FileTransferException
Put a local file onto the FTP server.- Parameters:
localPath
- path of the local fileremoteFile
- name of remote fileappend
- true if appending, false otherwise- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
put(InputStream, String, boolean)
withappend=false
.
-
put
void put(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append) throws java.io.IOException, FileTransferException
Put a stream of data onto the FTP server.- Parameters:
srcStream
- input stream of data to putremoteFile
- name of remote fileappend
- true if appending, false otherwise- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
put
default void put(byte[] bytes, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Put data onto the FTP server.- Parameters:
bytes
- array of bytesremoteFile
- name of remote file- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
put(InputStream, String, boolean)
withappend=false
.
-
put
default void put(byte[] bytes, java.lang.String remoteFile, boolean append) throws java.io.IOException, FileTransferException
Put data onto the FTP server.- Parameters:
bytes
- array of bytesremoteFile
- name of remote fileappend
- true if appending, false otherwise- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
put(InputStream, String, boolean)
.
-
get
default void get(java.lang.String localPath, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Get data from the FTP server.- Parameters:
localPath
- local file to put data inremoteFile
- name of remote file- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
get(OutputStream, String)
.
-
get
void get(java.io.OutputStream destStream, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Get data from the FTP server.- Parameters:
destStream
- data stream to write data toremoteFile
- name of remote file- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
get
byte[] get(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Get data from the FTP server.- Parameters:
remoteFile
- name of remote file- Returns:
- a byte array.
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
dir
default java.lang.String[] dir() throws java.io.IOException, FileTransferException
List current directory's contents as an array of strings of filenames.- Returns:
- an array of current directory listing strings
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
dir(String, boolean)
withdirname=null, full=false
.
-
dir
default java.lang.String[] dir(java.lang.String dirname) throws java.io.IOException, FileTransferException
List a directory's contents as an array of strings of filenames.- Parameters:
dirname
- name of directory(not a file mask)- Returns:
- an array of directory listing strings
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs- Implementation Note:
- The default implementation calls
dir(String, boolean)
withfull=false
.
-
dir
java.lang.String[] dir(java.lang.String dirname, boolean full) throws java.io.IOException, FileTransferException
List a directory's contents as an array of strings.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.
- Parameters:
dirname
- name of directory (not a file mask)full
- true if detailed listing required false otherwise- Returns:
- an array of directory listing strings
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
dir
java.lang.String[] dir(java.lang.String directory, java.io.FileFilter filter) throws FileTransferException, java.io.IOException
List a directory's contentsNote that although we use a standard
FileFilter
interface here operating onFile
; it actually usesRemoteFile
instead which overrides information that can be obtained from the remote server. Other standardFile
operations will not be supported, and may ultimately cause a runtime exception.- Parameters:
directory
- the directory to list.filter
- the filefilter mask to use- Returns:
- an array of strings containing the listing
- Throws:
java.io.IOException
- on comms error.FileTransferException
- on FTP Specific exception error.
-
delete
void delete(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
Delete the specified remote file- Parameters:
remoteFile
- name of remote file to delete- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
rename
void rename(java.lang.String from, java.lang.String to) throws java.io.IOException, FileTransferException
Rename a file or directory- Parameters:
from
- name of file or directory to renameto
- intended name- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
rmdir
void rmdir(java.lang.String dir) throws java.io.IOException, FileTransferException
Delete the specified remote working directory- Parameters:
dir
- name of remote directory to delete- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
mkdir
void mkdir(java.lang.String dir) throws java.io.IOException, FileTransferException
Create the specified remote working directory- Parameters:
dir
- name of remote directory to create- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
chdir
void chdir(java.lang.String dir) throws java.io.IOException, FileTransferException
Change the remote working directory to that supplied- Parameters:
dir
- name of remote directory to change to- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
isDirectory
boolean isDirectory(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
disconnect
void disconnect() throws java.io.IOException, FileTransferException
Quit the FTP session- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
lastModified
long lastModified(java.lang.String path) throws java.io.IOException, FileTransferException
Return the last modified time for the given path.- Parameters:
path
- the path to the filename.- Returns:
- the last modified time
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
lastModifiedDate
java.util.Date lastModifiedDate(java.lang.String path) throws java.io.IOException, FileTransferException
Return the last modified date for the given path.- Parameters:
path
- the path to the filename.- Returns:
- the date.
- Throws:
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurs
-
getKeepAliveTimeout
long getKeepAliveTimeout() throws FileTransferException
Get the time to wait between sending control connection keepalive messages.- Returns:
- time in seconds
- Throws:
FileTransferException
-
setKeepAliveTimeout
void setKeepAliveTimeout(long seconds) throws FileTransferException
Set the time to wait between sending control connection keepalive messages when processing file upload or download.- Parameters:
seconds
- time in seconds- Throws:
FileTransferException
-
isConnected
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- Returns:
- true = connected, false = not connected or some error
-
setAdditionalDebug
void setAdditionalDebug(boolean b)
Switch additional debug on or off- Parameters:
b
- set to true if you wish to get some additional debugging in the log file, defaults to false
-
close
default void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-