public class FTPClient extends Object
setMode()
, setType()
that
affect data channel settings must be called before passive
or active data channel mode is set.Modifier and Type | Field and Description |
---|---|
protected List<String> |
algorithms
List of the checksum algorithms supported by the server as described in
GridFTP v2 Protocol Description
|
protected FTPControlChannel |
controlChannel |
protected SimpleDateFormat |
dateFormat |
protected FTPServerFacade |
localServer |
static Pattern |
portPattern
Regular expression for matching the port information of a
GFD.47 127 reply.
|
protected Session |
session |
protected boolean |
useAllo
Whether to use ALLO with put()/asyncPut() or not
|
protected String |
username |
Modifier | Constructor and Description |
---|---|
protected |
FTPClient() |
|
FTPClient(String host,
int port)
Constructs client and connects it to the remote server.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the current transfer.
|
protected void |
actualSetMode(int mode,
String modeStr) |
void |
allocate(long size)
Reserve sufficient storage to accommodate the new file to be
transferred.
|
TransferState |
asynchGet(String remoteFileName,
DataSink sink,
MarkerListener mListener)
Retrieves the file from the remote server.
|
TransferState |
asynchGet2(String remoteFileName,
boolean passive,
DataSink sink,
MarkerListener mListener)
Retrieves a file asynchronously using the GFD.47 (a.k.a
GridFTP2) GET command.
|
TransferState |
asynchPut(String remoteFileName,
DataSource source,
MarkerListener mListener)
Stores file at the remote server.
|
TransferState |
asynchPut(String remoteFileName,
DataSource source,
MarkerListener mListener,
boolean append)
Stores file at the remote server.
|
TransferState |
asynchPut2(String remoteFileName,
boolean passive,
DataSource source,
MarkerListener mListener)
Stores a file at the remote server using the GFD.47 (a.k.a
GridFTP2) PUT command.
|
void |
authorize(String user,
String password)
Performs user authorization with specified
user and password.
|
void |
changeDir(String dir)
Changes the remote current working directory.
|
protected void |
checkGETPUTSupport()
Throws ServerException if GFD.47 GETPUT is not supported or
cannot be used.
|
protected void |
checkTransferParams() |
protected void |
checkTransferParamsGet() |
protected void |
checkTransferParamsPut() |
void |
close()
Closes connection.
|
void |
close(boolean ignoreQuitReply)
Closes connection.
|
void |
deleteDir(String dir)
Deletes the remote directory.
|
void |
deleteFile(String filename)
Deletes the remote file.
|
boolean |
exists(String filename)
Checks if given file/directory exists on the server.
|
void |
get(String remoteFileName,
DataSink sink,
MarkerListener mListener)
Retrieves the file from the remote server.
|
void |
get(String remoteFileName,
File localFile) |
protected HostPort |
get127Reply()
Reads a GFD.47 compliant 127 reply and extracts the port
information from it.
|
void |
get2(String remoteFileName,
boolean passive,
DataSink sink,
MarkerListener mListener)
Retrieves a file using the GFD.47 (a.k.a GridFTP2) GET command.
|
String |
getChecksum(String algorithm,
long offset,
long length,
String path)
implement GridFTP v2 CKSM command from
GridFTP v2 Protocol Description
|
String |
getChecksum(String algorithm,
String path)
GridFTP v2 CKSM command for the whole file
|
String |
getCurrentDir()
Returns remote current working directory.
|
FeatureList |
getFeatureList()
Returns list of features supported by remote server.
|
String |
getHost() |
Date |
getLastModified(String filename)
Returns last modification time of the specifed file.
|
Reply |
getLastReply()
Returns the last reply received from the server.
|
protected String |
getModeStr(int mode) |
int |
getPort() |
long |
getSize(String filename)
Returns the remote file size.
|
List<String> |
getSupportedCksumAlgorithms()
According to
GridFTP v2 Protocol Description
checksum feature has the following syntax:
|
boolean |
getUseAllo()
Determines whether this client is configured to send an ALLO
command before a STOR request in the put/asyncPut methods.
|
String |
getUserName() |
void |
goUpDir()
Changes remote current working directory to the higher level.
|
boolean |
isActiveMode() |
boolean |
isCksumAlgorithmSupported(String algorithm) |
boolean |
isFeatureSupported(String feature)
Returns true if the given feature is supported by remote server,
false otherwise.
|
boolean |
isPassiveMode() |
Date |
lastModified(String filename) |
Vector |
list()
Performs remote directory listing.
|
Vector |
list(String filter)
Performs remote directory listing with the specified filter.
|
Vector |
list(String filter,
String modifier)
Performs remote directory listing with the specified filter and
modifier.
|
void |
list(String filter,
String modifier,
DataSink sink)
Performs directory listing and writes the result
to the supplied data sink.
|
protected void |
listCheck()
check performed at the beginning of list()
|
void |
makeDir(String dir)
Creates remote directory.
|
Vector |
mlsd()
Performs remote directory listing of the current directory.
|
Vector |
mlsd(String path)
Performs remote directory listing on the given path.
|
void |
mlsd(String path,
DataSink sink)
Performs remote directory listing on the given path.
|
MlsxEntry |
mlst(String fileName)
Get info of a certain remote file in Mlsx format.
|
Vector |
nlist()
Performs remote directory listing of the current directory.
|
Vector |
nlist(String path)
Performs remote directory listing on the given path.
|
void |
nlist(String path,
DataSink sink)
Performs remote directory listing on the given path.
|
protected void |
performTransfer(Command cmd,
DataSink sink) |
void |
put(File localFile,
String remoteFileName,
boolean append) |
void |
put(String remoteFileName,
DataSource source,
MarkerListener mListener)
Stores file at the remote server.
|
void |
put(String remoteFileName,
DataSource source,
MarkerListener mListener,
boolean append)
Stores file at the remote server.
|
void |
put2(String remoteFileName,
boolean passive,
DataSource source,
MarkerListener mListener)
Stores a file at the remote server using the GFD.47 (a.k.a
GridFTP2) PUT command.
|
Reply |
quote(String command)
Executes arbitrary operation on the server.
|
void |
rename(String oldName,
String newName)
Renames remote directory.
|
void |
setActive()
Sets remote server active, telling it to connect to the client.
|
void |
setActive(HostPort hostPort)
Sets remote server active, telling it to connect to the given
address.
|
void |
setChecksum(String algorithm,
String value)
implement GridFTP v2 SCKS command as described in
GridFTP v2 Protocol Description
|
void |
setClientWaitParams(int maxWait,
int waitDelay)
Changes the default client timeout parameters.
|
void |
setLocalActive()
Starts local server in active server mode.
|
HostPort |
setLocalPassive()
Starts local server in passive server mode, with default parameters.
|
HostPort |
setLocalPassive(int port,
int queue)
Starts the local server in passive server mode.
|
void |
setMode(int mode)
Sets transfer mode.
|
void |
setOptions(Options opts)
Sets the supplied options to the server.
|
HostPort |
setPassive()
Sets remote server to passive server mode.
|
void |
setPassiveMode(boolean passiveMode)
Enables/disables passive data connections.
|
void |
setProtectionBufferSize(int size)
Sets protection buffer size (defined in RFC 2228)
|
void |
setRestartMarker(RestartData restartData)
Sets restart parameter of the next transfer.
|
void |
setType(int type)
Sets transfer type.
|
void |
setUseAllo(boolean useAllo)
Controls whether the client attempts to send an ALLO command
before a STOR request during the put/asyncPut calls.
|
Reply |
site(String args)
Executes site-specific operation (using the SITE command).
|
long |
size(String filename) |
static void |
transfer(FTPClient source,
String remoteSrcFile,
FTPClient destination,
String remoteDstFile,
int mode,
MarkerListener mListener)
Performs third-party transfer between two servers.
|
void |
transfer(String remoteSrcFile,
FTPClient destination,
String remoteDstFile,
boolean append,
MarkerListener mListener)
Performs third-party transfer between two servers.
|
protected TransferState |
transferBegin(BasicClientControlChannel other,
MarkerListener mListener) |
protected void |
transferRun(BasicClientControlChannel other,
MarkerListener mListener)
Actual transfer management.
|
protected void |
transferRunSingleThread(BasicClientControlChannel other,
MarkerListener mListener) |
protected TransferState |
transferStart(BasicClientControlChannel other,
MarkerListener mListener) |
protected void |
transferWait(TransferState transferState) |
protected Session session
protected FTPControlChannel controlChannel
protected FTPServerFacade localServer
protected SimpleDateFormat dateFormat
protected String username
protected boolean useAllo
protected List<String> algorithms
public static final Pattern portPattern
protected FTPClient()
public FTPClient(String host, int port) throws IOException, ServerException
host
- remote server hostport
- remote server portIOException
ServerException
public String getHost()
public int getPort()
public Reply getLastReply()
public long getSize(String filename) throws IOException, ServerException
filename
- filename get the size for.ServerException
- if the file does not exist or
an error occured.IOException
public Date getLastModified(String filename) throws IOException, ServerException
filename
- filename get the last modification time for.ServerException
- if the file does not exist or
an error occured.IOException
public boolean exists(String filename) throws IOException, ServerException
filename
- file or directory nameIOException
ServerException
public void changeDir(String dir) throws IOException, ServerException
IOException
ServerException
public void deleteDir(String dir) throws IOException, ServerException
IOException
ServerException
public void deleteFile(String filename) throws IOException, ServerException
IOException
ServerException
public void makeDir(String dir) throws IOException, ServerException
IOException
ServerException
public void rename(String oldName, String newName) throws IOException, ServerException
IOException
ServerException
public String getCurrentDir() throws IOException, ServerException
IOException
ServerException
public void goUpDir() throws IOException, ServerException
IOException
ServerException
public Vector list() throws ServerException, ClientException, IOException
mlsd()
function instead.FileInfo
objects, representing
remote filesServerException
ClientException
IOException
mlsd()
public Vector list(String filter) throws ServerException, ClientException, IOException
mlsd()
function instead. filter
- "*" for example, can be null.FileInfo
objects, representing
remote filesServerException
ClientException
IOException
mlsd(String)
public Vector list(String filter, String modifier) throws ServerException, ClientException, IOException
mlsd()
function instead.filter
- "*" for example, can be null.modifier
- "-d" for example, can be null.FileInfo
objects, representing
remote filesServerException
ClientException
IOException
mlsd(String)
public void list(String filter, String modifier, DataSink sink) throws ServerException, ClientException, IOException
mlsd()
function instead.filter
- remote list command file filter, eg. "*"modifier
- remote list command modifier, eg. "-d"sink
- data destinationServerException
ClientException
IOException
public Vector nlist() throws ServerException, ClientException, IOException
FileInfo
objects, representing
remote filesServerException
ClientException
IOException
public Vector nlist(String path) throws ServerException, ClientException, IOException
path
- directory to perform listing of. If null, listing
of current directory will be performed.FileInfo
objects, representing
remote filesServerException
ClientException
IOException
public void nlist(String path, DataSink sink) throws ServerException, ClientException, IOException
path
- directory to perform listing of. If null, listing
of current directory will be performed.sink
- sink to which the listing data will be written.ServerException
ClientException
IOException
public MlsxEntry mlst(String fileName) throws IOException, ServerException
IOException
ServerException
public Vector mlsd() throws ServerException, ClientException, IOException
MlsxEntry
objects, representing
remote filesServerException
ClientException
IOException
public Vector mlsd(String path) throws ServerException, ClientException, IOException
path
- directory to perform listing of. If null, listing
of current directory will be performed.MlsxEntry
objects, representing
remote filesServerException
ClientException
IOException
public void mlsd(String path, DataSink sink) throws ServerException, ClientException, IOException
path
- directory to perform listing of. If null, listing
of current directory will be performed.sink
- sink to which the listing data will be written.ServerException
ClientException
IOException
protected void listCheck() throws ClientException
ClientException
protected void checkTransferParamsGet() throws ServerException, IOException, ClientException
protected void checkTransferParamsPut() throws ServerException, IOException, ClientException
protected void checkTransferParams() throws ServerException, IOException, ClientException
protected void performTransfer(Command cmd, DataSink sink) throws ServerException, ClientException, IOException
public void setType(int type) throws IOException, ServerException
type
- should be TYPE_IMAGE
,
TYPE_ASCII
,
TYPE_LOCAL
,
TYPE_EBCDIC
IOException
ServerException
protected String getModeStr(int mode)
public void setMode(int mode) throws IOException, ServerException
mode
- should be MODE_STREAM
,
MODE_BLOCK
IOException
ServerException
protected void actualSetMode(int mode, String modeStr) throws IOException, ServerException
IOException
ServerException
public void setProtectionBufferSize(int size) throws IOException, ServerException
size
- the size of bufferIOException
ServerException
public void abort() throws IOException, ServerException
IOException
ServerException
public void close() throws IOException, ServerException
IOException
ServerException
public void close(boolean ignoreQuitReply) throws IOException, ServerException
ignoreQuitReply
- if true the QUIT
command
will be sent but the client will not wait for the
server's reply. If false, the client will block
for the server's reply.IOException
ServerException
public boolean isFeatureSupported(String feature) throws IOException, ServerException
IOException
ServerException
public FeatureList getFeatureList() throws IOException, ServerException
IOException
ServerException
public HostPort setPassive() throws IOException, ServerException
IOException
ServerException
public void setActive(HostPort hostPort) throws IOException, ServerException
hostPort
- the address to which the server should connectIOException
ServerException
public void setActive() throws IOException, ServerException, ClientException
public void setLocalActive() throws ClientException, IOException
ClientException
IOException
public HostPort setLocalPassive() throws IOException
IOException
public HostPort setLocalPassive(int port, int queue) throws IOException
port
- port at which local server should be listening;
can be set to FTPServerFacade.ANY_PORTqueue
- max size of queue of awaiting new connection
requestsIOException
public void setClientWaitParams(int maxWait, int waitDelay)
maxWait
- timeout in milisecondswaitDelay
- polling periodpublic void setOptions(Options opts) throws IOException, ServerException
IOException
ServerException
public void setRestartMarker(RestartData restartData) throws IOException, ServerException
restartData
- marker to useServerException
- if the file does not exist or
an error occured.IOException
public void authorize(String user, String password) throws IOException, ServerException
user
- usernamepassword
- user passwordServerException
- on server refusalIOException
public String getUserName()
public void get(String remoteFileName, DataSink sink, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- remote file namesink
- sink to which the data will be writtenmListener
- restart marker listener (currently not used)IOException
ClientException
ServerException
public TransferState asynchGet(String remoteFileName, DataSink sink, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- remote file namesink
- sink to which the data will be writtenmListener
- restart marker listener (currently not used)IOException
ClientException
ServerException
public void put(String remoteFileName, DataSource source, MarkerListener mListener) throws IOException, ServerException, ClientException
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)IOException
ServerException
ClientException
public void put(String remoteFileName, DataSource source, MarkerListener mListener, boolean append) throws IOException, ServerException, ClientException
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)append
- append to the end of file or overwriteIOException
ServerException
ClientException
public TransferState asynchPut(String remoteFileName, DataSource source, MarkerListener mListener) throws IOException, ServerException, ClientException
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)IOException
ServerException
ClientException
public TransferState asynchPut(String remoteFileName, DataSource source, MarkerListener mListener, boolean append) throws IOException, ServerException, ClientException
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)append
- append to the end of file or overwriteIOException
ServerException
ClientException
public void transfer(String remoteSrcFile, FTPClient destination, String remoteDstFile, boolean append, MarkerListener mListener) throws IOException, ServerException, ClientException
remoteSrcFile
- source filenamedestination
- another client connected to destination serverremoteDstFile
- destination filenameappend
- enables append mode; if true,
data will be appened to the remote file, otherwise
file will be overwritten.mListener
- marker listener.
Can be set to null.IOException
ServerException
ClientException
protected void transferRun(BasicClientControlChannel other, MarkerListener mListener) throws IOException, ServerException, ClientException
protected TransferState transferBegin(BasicClientControlChannel other, MarkerListener mListener)
protected TransferState transferStart(BasicClientControlChannel other, MarkerListener mListener) throws IOException, ServerException, ClientException
protected void transferWait(TransferState transferState) throws IOException, ServerException, ClientException
protected void transferRunSingleThread(BasicClientControlChannel other, MarkerListener mListener) throws IOException, ServerException, ClientException
public Reply quote(String command) throws IOException, ServerException
command
- command to executeIOException
- in case of I/O error.ServerException
- if operation failed.public Reply site(String args) throws IOException, ServerException
args
- parameters for the SITE operation.IOException
- in case of I/O errorServerException
- if operation failed.public void allocate(long size) throws IOException, ServerException
size
- the amount of space to reserveServerException
- if an error occured.IOException
public long size(String filename) throws IOException, ServerException
IOException
ServerException
public Date lastModified(String filename) throws IOException, ServerException
IOException
ServerException
public void get(String remoteFileName, File localFile) throws IOException, ClientException, ServerException
public void put(File localFile, String remoteFileName, boolean append) throws IOException, ServerException, ClientException
public void setPassiveMode(boolean passiveMode) throws IOException, ClientException, ServerException
passiveMode
- if true passive connections will be
established. If false, they will not.IOException
ClientException
ServerException
public boolean isPassiveMode()
protected void checkGETPUTSupport() throws ServerException, IOException
ServerException
IOException
protected HostPort get127Reply() throws ServerException, IOException, FTPReplyParseException
public void get2(String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesink
- data sink to store the filemListener
- marker listenerIOException
ClientException
ServerException
public TransferState asynchGet2(String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesink
- data sink to store the filemListener
- marker listenerIOException
ClientException
ServerException
public void put2(String remoteFileName, boolean passive, DataSource source, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesource
- data will be read from heremListener
- marker listenerIOException
ClientException
ServerException
public TransferState asynchPut2(String remoteFileName, boolean passive, DataSource source, MarkerListener mListener) throws IOException, ClientException, ServerException
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesource
- data will be read from heremListener
- marker listenerIOException
ClientException
ServerException
public static void transfer(FTPClient source, String remoteSrcFile, FTPClient destination, String remoteDstFile, int mode, MarkerListener mListener) throws IOException, ServerException, ClientException
source
- client connected to source serverremoteSrcFile
- source filenamedestination
- client connected to destination serverremoteDstFile
- destination filenamemode
- data channel mode or 0 to use the current modemListener
- marker listener.
Can be set to null.IOException
ServerException
ClientException
public boolean isActiveMode()
public void setUseAllo(boolean useAllo)
useAllo
- true
if the client should try
to send an ALLO command before a STOR requestpublic boolean getUseAllo()
public List<String> getSupportedCksumAlgorithms() throws ClientException, ServerException, IOException
CKSUMgetSupportedCksumAlgorithms parses checsum feauture parms and form a list of checksum algorithms supported by the server[, …]
ClientException
org.globus.ftp.org.globus.ftp.exception.ServerException
IOException
ServerException
public boolean isCksumAlgorithmSupported(String algorithm) throws ClientException, ServerException, IOException
public String getChecksum(String algorithm, long offset, long length, String path) throws ClientException, ServerException, IOException
5.1 CKSM This command is used by the client to request checksum calculation over a portion or whole file existing on the server. The syntax is: CKSMCRLF Server executes this command by calculating specified type of checksum over portion of the file starting at the offset and of the specified length. If length is –1, the checksum will be calculated through the end of the file. On success, the server replies with 2xx Actual format of checksum value depends on the algorithm used, but generally, hexadecimal representation should be used.
algorithm
- ckeckum alorithmoffset
- length
- path
- ClientException
org.globus.ftp.org.globus.ftp.exception.ServerException
IOException
ServerException
public String getChecksum(String algorithm, String path) throws ClientException, ServerException, IOException
algorithm
- ckeckum alorithmpath
- ClientException
org.globus.ftp.org.globus.ftp.exception.ServerException
IOException
ServerException
public void setChecksum(String algorithm, String value) throws ClientException, ServerException, IOException
5.2 SCKS This command is sent prior to upload command such as STOR, ESTO, PUT. It is used to convey to the server that the checksum value for the file which is about to be uploaded. At the end of transfer, server will calculate checksum for the received file, and if it does not match, will consider the transfer to have failed. Syntax of the command is: SCKSCRLF Actual format of checksum value depends on the algorithm used, but generally, hexadecimal representation should be used.
algorithm
- value
- ClientException
org.globus.ftp.org.globus.ftp.exception.ServerException
IOException
ServerException
Copyright © 2016. All rights reserved.