Package org.globus.ftp
Class FTPClient
- java.lang.Object
-
- org.globus.ftp.FTPClient
-
- Direct Known Subclasses:
GridFTPClient
public class FTPClient extends java.lang.Object
This is the main user interface for FTP operations. Use this class for client - server or third party transfers that do not require GridFTP extensions. Consult the manual for general usage.
Note: If using with GridFTP servers operations likesetMode()
,setType()
that affect data channel settings must be called before passive or active data channel mode is set.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.String>
algorithms
List of the checksum algorithms supported by the server as described in GridFTP v2 Protocol Descriptionprotected FTPControlChannel
controlChannel
protected java.text.SimpleDateFormat
dateFormat
protected FTPServerFacade
localServer
static java.util.regex.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 notprotected java.lang.String
username
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Aborts the current transfer.protected void
actualSetMode(int mode, java.lang.String modeStr)
void
allocate(long size)
Reserve sufficient storage to accommodate the new file to be transferred.TransferState
asynchGet(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener)
Retrieves the file from the remote server.TransferState
asynchGet2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener)
Retrieves a file asynchronously using the GFD.47 (a.k.a GridFTP2) GET command.TransferState
asynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)
Stores file at the remote server.TransferState
asynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append)
Stores file at the remote server.TransferState
asynchPut2(java.lang.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(java.lang.String user, java.lang.String password)
Performs user authorization with specified user and password.void
changeDir(java.lang.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(java.lang.String dir)
Deletes the remote directory.void
deleteFile(java.lang.String filename)
Deletes the remote file.boolean
exists(java.lang.String filename)
Checks if given file/directory exists on the server.void
get(java.lang.String remoteFileName, java.io.File localFile)
void
get(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener)
Retrieves the file from the remote server.protected HostPort
get127Reply()
Reads a GFD.47 compliant 127 reply and extracts the port information from it.void
get2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener)
Retrieves a file using the GFD.47 (a.k.a GridFTP2) GET command.java.lang.String
getChecksum(java.lang.String algorithm, long offset, long length, java.lang.String path)
implement GridFTP v2 CKSM command from GridFTP v2 Protocol Descriptionjava.lang.String
getChecksum(java.lang.String algorithm, java.lang.String path)
GridFTP v2 CKSM command for the whole filejava.lang.String
getCurrentDir()
Returns remote current working directory.FeatureList
getFeatureList()
Returns list of features supported by remote server.java.lang.String
getHost()
java.util.Date
getLastModified(java.lang.String filename)
Returns last modification time of the specifed file.Reply
getLastReply()
Returns the last reply received from the server.protected java.lang.String
getModeStr(int mode)
int
getPort()
long
getSize(java.lang.String filename)
Returns the remote file size.java.util.List<java.lang.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.java.lang.String
getUserName()
void
goUpDir()
Changes remote current working directory to the higher level.boolean
isActiveMode()
boolean
isCksumAlgorithmSupported(java.lang.String algorithm)
boolean
isFeatureSupported(java.lang.String feature)
Returns true if the given feature is supported by remote server, false otherwise.boolean
isPassiveMode()
java.util.Date
lastModified(java.lang.String filename)
java.util.Vector
list()
Performs remote directory listing.java.util.Vector
list(java.lang.String filter)
Performs remote directory listing with the specified filter.java.util.Vector
list(java.lang.String filter, java.lang.String modifier)
Performs remote directory listing with the specified filter and modifier.void
list(java.lang.String filter, java.lang.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(java.lang.String dir)
Creates remote directory.java.util.Vector
mlsd()
Performs remote directory listing of the current directory.java.util.Vector
mlsd(java.lang.String path)
Performs remote directory listing on the given path.void
mlsd(java.lang.String path, DataSink sink)
Performs remote directory listing on the given path.MlsxEntry
mlst(java.lang.String fileName)
Get info of a certain remote file in Mlsx format.java.util.Vector
nlist()
Performs remote directory listing of the current directory.java.util.Vector
nlist(java.lang.String path)
Performs remote directory listing on the given path.void
nlist(java.lang.String path, DataSink sink)
Performs remote directory listing on the given path.protected void
performTransfer(Command cmd, DataSink sink)
void
put(java.io.File localFile, java.lang.String remoteFileName, boolean append)
void
put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)
Stores file at the remote server.void
put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append)
Stores file at the remote server.void
put2(java.lang.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(java.lang.String command)
Executes arbitrary operation on the server.void
rename(java.lang.String oldName, java.lang.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(java.lang.String algorithm, java.lang.String value)
implement GridFTP v2 SCKS command as described in GridFTP v2 Protocol Descriptionvoid
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(java.lang.String args)
Executes site-specific operation (using the SITE command).long
size(java.lang.String filename)
void
transfer(java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, boolean append, MarkerListener mListener)
Performs third-party transfer between two servers.static void
transfer(FTPClient source, java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, int mode, 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)
-
-
-
Field Detail
-
session
protected Session session
-
controlChannel
protected FTPControlChannel controlChannel
-
localServer
protected FTPServerFacade localServer
-
dateFormat
protected java.text.SimpleDateFormat dateFormat
-
username
protected java.lang.String username
-
useAllo
protected boolean useAllo
Whether to use ALLO with put()/asyncPut() or not
-
algorithms
protected java.util.List<java.lang.String> algorithms
List of the checksum algorithms supported by the server as described in GridFTP v2 Protocol Description
-
portPattern
public static final java.util.regex.Pattern portPattern
Regular expression for matching the port information of a GFD.47 127 reply.
-
-
Constructor Detail
-
FTPClient
protected FTPClient()
-
FTPClient
public FTPClient(java.lang.String host, int port) throws java.io.IOException, ServerException
Constructs client and connects it to the remote server.- Parameters:
host
- remote server hostport
- remote server port- Throws:
java.io.IOException
ServerException
-
-
Method Detail
-
getHost
public java.lang.String getHost()
-
getPort
public int getPort()
-
getLastReply
public Reply getLastReply()
Returns the last reply received from the server. This could be used immediately after the call to the constructor to get the initial server reply
-
getSize
public long getSize(java.lang.String filename) throws java.io.IOException, ServerException
Returns the remote file size.- Parameters:
filename
- filename get the size for.- Returns:
- size of the file.
- Throws:
ServerException
- if the file does not exist or an error occured.java.io.IOException
-
getLastModified
public java.util.Date getLastModified(java.lang.String filename) throws java.io.IOException, ServerException
Returns last modification time of the specifed file.- Parameters:
filename
- filename get the last modification time for.- Returns:
- the time and date of the last modification.
- Throws:
ServerException
- if the file does not exist or an error occured.java.io.IOException
-
exists
public boolean exists(java.lang.String filename) throws java.io.IOException, ServerException
Checks if given file/directory exists on the server.- Parameters:
filename
- file or directory name- Returns:
- true if the file exists, false otherwise.
- Throws:
java.io.IOException
ServerException
-
changeDir
public void changeDir(java.lang.String dir) throws java.io.IOException, ServerException
Changes the remote current working directory.- Throws:
java.io.IOException
ServerException
-
deleteDir
public void deleteDir(java.lang.String dir) throws java.io.IOException, ServerException
Deletes the remote directory.- Throws:
java.io.IOException
ServerException
-
deleteFile
public void deleteFile(java.lang.String filename) throws java.io.IOException, ServerException
Deletes the remote file.- Throws:
java.io.IOException
ServerException
-
makeDir
public void makeDir(java.lang.String dir) throws java.io.IOException, ServerException
Creates remote directory.- Throws:
java.io.IOException
ServerException
-
rename
public void rename(java.lang.String oldName, java.lang.String newName) throws java.io.IOException, ServerException
Renames remote directory.- Throws:
java.io.IOException
ServerException
-
getCurrentDir
public java.lang.String getCurrentDir() throws java.io.IOException, ServerException
Returns remote current working directory.- Returns:
- remote current working directory.
- Throws:
java.io.IOException
ServerException
-
goUpDir
public void goUpDir() throws java.io.IOException, ServerException
Changes remote current working directory to the higher level.- Throws:
java.io.IOException
ServerException
-
list
public java.util.Vector list() throws ServerException, ClientException, java.io.IOException
Performs remote directory listing. Sends 'LIST -d *' command.
Note: This function can only parse Unix ls -d like output. Please note that the LIST output is unspecified in the FTP standard and each server might return slightly different output causing the parsing to fail. Also, if the ftp server does not accept -d option or support wildcards, this method might fail. For example, this command will fail on GridFTP server distributed with GT 4.0.0. It is strongly recommended to usemlsd()
function instead.- Returns:
- Vector list of
FileInfo
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
- See Also:
mlsd()
-
list
public java.util.Vector list(java.lang.String filter) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing with the specified filter. Sends 'LIST -d <filter>' command.
Note: This function can only parse Unix ls -d like output. Please note that the LIST output is unspecified in the FTP standard and each server might return slightly different output causing the parsing to fail. Also, if the ftp server does not accept -d option or support wildcards, this method might fail. For example, this command will fail on GridFTP server distributed with GT 4.0.0. It is strongly recommended to usemlsd()
function instead.- Parameters:
filter
- "*" for example, can be null.- Returns:
- Vector list of
FileInfo
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
- See Also:
mlsd(String)
-
list
public java.util.Vector list(java.lang.String filter, java.lang.String modifier) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing with the specified filter and modifier. Sends 'LIST <modifier> <filter>' command.
Note: This function can only parse Unix ls -d like output. Please note that the LIST output is unspecified in the FTP standard and each server might return slightly different output causing the parsing to fail. Also, please keep in mind that the ftp server might not recognize or support all the different modifiers or filters. In fact, some servers such as GridFTP server distributed with GT 4.0.0 does not support any modifiers or filters (strict RFC 959 compliance). It is strongly recommended to usemlsd()
function instead.- Parameters:
filter
- "*" for example, can be null.modifier
- "-d" for example, can be null.- Returns:
- Vector list of
FileInfo
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
- See Also:
mlsd(String)
-
list
public void list(java.lang.String filter, java.lang.String modifier, DataSink sink) throws ServerException, ClientException, java.io.IOException
Performs directory listing and writes the result to the supplied data sink. This method is allowed in ASCII mode only.
Note: Please keep in mind that the ftp server might not recognize or support all the different modifiers or filters. In fact, some servers such as GridFTP server distributed with GT 4.0.0 does not support any modifiers or filters (strict RFC 959 compliance). It is strongly recommended to usemlsd()
function instead.- Parameters:
filter
- remote list command file filter, eg. "*"modifier
- remote list command modifier, eg. "-d"sink
- data destination- Throws:
ServerException
ClientException
java.io.IOException
-
nlist
public java.util.Vector nlist() throws ServerException, ClientException, java.io.IOException
Performs remote directory listing of the current directory. Sends 'NLST' command.- Returns:
- Vector list of
FileInfo
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
-
nlist
public java.util.Vector nlist(java.lang.String path) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing on the given path. Sends 'NLST <path>' command.- Parameters:
path
- directory to perform listing of. If null, listing of current directory will be performed.- Returns:
- Vector list of
FileInfo
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
-
nlist
public void nlist(java.lang.String path, DataSink sink) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing on the given path. Sends 'NLST <path>' command.- Parameters:
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.- Throws:
ServerException
ClientException
java.io.IOException
-
mlst
public MlsxEntry mlst(java.lang.String fileName) throws java.io.IOException, ServerException
Get info of a certain remote file in Mlsx format.- Throws:
java.io.IOException
ServerException
-
mlsd
public java.util.Vector mlsd() throws ServerException, ClientException, java.io.IOException
Performs remote directory listing of the current directory. Sends 'MLSD' command.- Returns:
- Vector list of
MlsxEntry
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
-
mlsd
public java.util.Vector mlsd(java.lang.String path) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing on the given path. Sends 'MLSD <path>' command.- Parameters:
path
- directory to perform listing of. If null, listing of current directory will be performed.- Returns:
- Vector list of
MlsxEntry
objects, representing remote files - Throws:
ServerException
ClientException
java.io.IOException
-
mlsd
public void mlsd(java.lang.String path, DataSink sink) throws ServerException, ClientException, java.io.IOException
Performs remote directory listing on the given path. Sends 'MLSD <path>' command.- Parameters:
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.- Throws:
ServerException
ClientException
java.io.IOException
-
listCheck
protected void listCheck() throws ClientException
check performed at the beginning of list()- Throws:
ClientException
-
checkTransferParamsGet
protected void checkTransferParamsGet() throws ServerException, java.io.IOException, ClientException
- Throws:
ServerException
java.io.IOException
ClientException
-
checkTransferParamsPut
protected void checkTransferParamsPut() throws ServerException, java.io.IOException, ClientException
- Throws:
ServerException
java.io.IOException
ClientException
-
checkTransferParams
protected void checkTransferParams() throws ServerException, java.io.IOException, ClientException
- Throws:
ServerException
java.io.IOException
ClientException
-
performTransfer
protected void performTransfer(Command cmd, DataSink sink) throws ServerException, ClientException, java.io.IOException
- Throws:
ServerException
ClientException
java.io.IOException
-
setType
public void setType(int type) throws java.io.IOException, ServerException
Sets transfer type.- Parameters:
type
- should beTYPE_IMAGE
,TYPE_ASCII
,TYPE_LOCAL
,TYPE_EBCDIC
- Throws:
java.io.IOException
ServerException
-
getModeStr
protected java.lang.String getModeStr(int mode)
-
setMode
public void setMode(int mode) throws java.io.IOException, ServerException
Sets transfer mode.- Parameters:
mode
- should beMODE_STREAM
,MODE_BLOCK
- Throws:
java.io.IOException
ServerException
-
actualSetMode
protected void actualSetMode(int mode, java.lang.String modeStr) throws java.io.IOException, ServerException
- Throws:
java.io.IOException
ServerException
-
setProtectionBufferSize
public void setProtectionBufferSize(int size) throws java.io.IOException, ServerException
Sets protection buffer size (defined in RFC 2228)- Parameters:
size
- the size of buffer- Throws:
java.io.IOException
ServerException
-
abort
public void abort() throws java.io.IOException, ServerException
Aborts the current transfer. FTPClient is not thread safe so be careful with using this procedure, which will typically happen in multi threaded environment. Especially during client-server two party transfer, calling abort() may result with exceptions being thrown in the thread that currently perform the transfer.- Throws:
java.io.IOException
ServerException
-
close
public void close() throws java.io.IOException, ServerException
Closes connection. Sends QUIT command and closes connection even if the server reply was not positive. Also, closes the local server. This function will block until the server sends a reply to the QUIT command.- Throws:
java.io.IOException
ServerException
-
close
public void close(boolean ignoreQuitReply) throws java.io.IOException, ServerException
Closes connection. Sends QUIT and closes connection even if the server reply was not positive. Also, closes the local server.- Parameters:
ignoreQuitReply
- if true theQUIT
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.- Throws:
java.io.IOException
ServerException
-
isFeatureSupported
public boolean isFeatureSupported(java.lang.String feature) throws java.io.IOException, ServerException
Returns true if the given feature is supported by remote server, false otherwise.- Returns:
- true if the given feature is supported by remote server, false otherwise.
- Throws:
java.io.IOException
ServerException
-
getFeatureList
public FeatureList getFeatureList() throws java.io.IOException, ServerException
Returns list of features supported by remote server.- Returns:
- list of features supported by remote server.
- Throws:
java.io.IOException
ServerException
-
setPassive
public HostPort setPassive() throws java.io.IOException, ServerException
Sets remote server to passive server mode.- Returns:
- the address at which the server is listening.
- Throws:
java.io.IOException
ServerException
-
setActive
public void setActive(HostPort hostPort) throws java.io.IOException, ServerException
Sets remote server active, telling it to connect to the given address.- Parameters:
hostPort
- the address to which the server should connect- Throws:
java.io.IOException
ServerException
-
setActive
public void setActive() throws java.io.IOException, ServerException, ClientException
Sets remote server active, telling it to connect to the client. setLocalPassive() must be called beforehand.- Throws:
java.io.IOException
ServerException
ClientException
-
setLocalActive
public void setLocalActive() throws ClientException, java.io.IOException
Starts local server in active server mode.- Throws:
ClientException
java.io.IOException
-
setLocalPassive
public HostPort setLocalPassive() throws java.io.IOException
Starts local server in passive server mode, with default parameters. In other words, behaves like setLocalPassive(FTPServerFacade.ANY_PORT, FTPServerFacade.DEFAULT_QUEUE)- Throws:
java.io.IOException
-
setLocalPassive
public HostPort setLocalPassive(int port, int queue) throws java.io.IOException
Starts the local server in passive server mode.- Parameters:
port
- port at which local server should be listening; can be set to FTPServerFacade.ANY_PORTqueue
- max size of queue of awaiting new connection requests- Returns:
- the server address
- Throws:
java.io.IOException
-
setClientWaitParams
public void setClientWaitParams(int maxWait, int waitDelay)
Changes the default client timeout parameters. In the beginning of the transfer, the critical moment is the wait for the initial server reply. If it does not arrive after timeout, client assumes that the transfer could not start for some reason and aborts the operation. Default timeout in miliseconds is Session.DEFAULT_MAX_WAIT. During the waiting period, client polls the control channel once a certain period, which is by default set to Session.DEFAULT_WAIT_DELAY.
Use this method to change these parameters.- Parameters:
maxWait
- timeout in milisecondswaitDelay
- polling period
-
setOptions
public void setOptions(Options opts) throws java.io.IOException, ServerException
Sets the supplied options to the server.- Throws:
java.io.IOException
ServerException
-
setRestartMarker
public void setRestartMarker(RestartData restartData) throws java.io.IOException, ServerException
Sets restart parameter of the next transfer.- Parameters:
restartData
- marker to use- Throws:
ServerException
- if the file does not exist or an error occured.java.io.IOException
-
authorize
public void authorize(java.lang.String user, java.lang.String password) throws java.io.IOException, ServerException
Performs user authorization with specified user and password.- Parameters:
user
- usernamepassword
- user password- Throws:
ServerException
- on server refusaljava.io.IOException
-
getUserName
public java.lang.String getUserName()
-
get
public void get(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Retrieves the file from the remote server.- Parameters:
remoteFileName
- remote file namesink
- sink to which the data will be writtenmListener
- restart marker listener (currently not used)- Throws:
java.io.IOException
ClientException
ServerException
-
asynchGet
public TransferState asynchGet(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Retrieves the file from the remote server.- Parameters:
remoteFileName
- remote file namesink
- sink to which the data will be writtenmListener
- restart marker listener (currently not used)- Throws:
java.io.IOException
ClientException
ServerException
-
put
public void put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
Stores file at the remote server.- Parameters:
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)- Throws:
java.io.IOException
ServerException
ClientException
-
put
public void put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append) throws java.io.IOException, ServerException, ClientException
Stores file at the remote server.- Parameters:
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)append
- append to the end of file or overwrite- Throws:
java.io.IOException
ServerException
ClientException
-
asynchPut
public TransferState asynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
Stores file at the remote server.- Parameters:
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)- Throws:
java.io.IOException
ServerException
ClientException
-
asynchPut
public TransferState asynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append) throws java.io.IOException, ServerException, ClientException
Stores file at the remote server.- Parameters:
remoteFileName
- remote file namesource
- data will be read from heremListener
- restart marker listener (currently not used)append
- append to the end of file or overwrite- Throws:
java.io.IOException
ServerException
ClientException
-
transfer
public void transfer(java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, boolean append, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
Performs third-party transfer between two servers.- Parameters:
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.- Throws:
java.io.IOException
ServerException
ClientException
-
transferRun
protected void transferRun(BasicClientControlChannel other, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
Actual transfer management. Transfer is controlled by two new threads listening to the two servers.- Throws:
java.io.IOException
ServerException
ClientException
-
transferBegin
protected TransferState transferBegin(BasicClientControlChannel other, MarkerListener mListener)
-
transferStart
protected TransferState transferStart(BasicClientControlChannel other, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOException
ServerException
ClientException
-
transferWait
protected void transferWait(TransferState transferState) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOException
ServerException
ClientException
-
transferRunSingleThread
protected void transferRunSingleThread(BasicClientControlChannel other, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOException
ServerException
ClientException
-
quote
public Reply quote(java.lang.String command) throws java.io.IOException, ServerException
Executes arbitrary operation on the server.
Note: This is potentially dangerous operation. Depending on the command executed it might put the server in a different state from the state the client is expecting.- Parameters:
command
- command to execute- Returns:
- the Reply to the operation.
- Throws:
java.io.IOException
- in case of I/O error.ServerException
- if operation failed.
-
site
public Reply site(java.lang.String args) throws java.io.IOException, ServerException
Executes site-specific operation (using the SITE command).
Note: This is potentially dangerous operation. Depending on the command executed it might put the server in a different state from the state the client is expecting.- Parameters:
args
- parameters for the SITE operation.- Returns:
- the Reply to the operation.
- Throws:
java.io.IOException
- in case of I/O errorServerException
- if operation failed.
-
allocate
public void allocate(long size) throws java.io.IOException, ServerException
Reserve sufficient storage to accommodate the new file to be transferred.- Parameters:
size
- the amount of space to reserve- Throws:
ServerException
- if an error occured.java.io.IOException
-
size
public long size(java.lang.String filename) throws java.io.IOException, ServerException
- Throws:
java.io.IOException
ServerException
-
lastModified
public java.util.Date lastModified(java.lang.String filename) throws java.io.IOException, ServerException
- Throws:
java.io.IOException
ServerException
-
get
public void get(java.lang.String remoteFileName, java.io.File localFile) throws java.io.IOException, ClientException, ServerException
- Throws:
java.io.IOException
ClientException
ServerException
-
put
public void put(java.io.File localFile, java.lang.String remoteFileName, boolean append) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOException
ServerException
ClientException
-
setPassiveMode
public void setPassiveMode(boolean passiveMode) throws java.io.IOException, ClientException, ServerException
Enables/disables passive data connections.- Parameters:
passiveMode
- if true passive connections will be established. If false, they will not.- Throws:
java.io.IOException
ClientException
ServerException
-
isPassiveMode
public boolean isPassiveMode()
-
checkGETPUTSupport
protected void checkGETPUTSupport() throws ServerException, java.io.IOException
Throws ServerException if GFD.47 GETPUT is not supported or cannot be used.- Throws:
ServerException
java.io.IOException
-
get127Reply
protected HostPort get127Reply() throws ServerException, java.io.IOException, FTPReplyParseException
Reads a GFD.47 compliant 127 reply and extracts the port information from it.- Throws:
ServerException
java.io.IOException
FTPReplyParseException
-
get2
public void get2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Retrieves a file using the GFD.47 (a.k.a GridFTP2) GET command. Notice that as a side effect this method may change the local server facade passive/active mode setting. The caller should not rely on this setting after call to get2. Even though the active/passive status of the current session is ignored for the actual transfer, it still has to be in a consistent state prior to calling gridftp2Get.- Parameters:
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesink
- data sink to store the filemListener
- marker listener- Throws:
java.io.IOException
ClientException
ServerException
-
asynchGet2
public TransferState asynchGet2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Retrieves a file asynchronously using the GFD.47 (a.k.a GridFTP2) GET command. Notice that as a side effect this method may change the local server facade passive/active mode setting. The caller should not rely on this setting after call to gridftp2Get. Even though the active/passive status of the current session is ignored for the actual transfer, it still has to be in a consistent state prior to calling gridftp2Get.- Parameters:
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesink
- data sink to store the filemListener
- marker listener- Throws:
java.io.IOException
ClientException
ServerException
-
put2
public void put2(java.lang.String remoteFileName, boolean passive, DataSource source, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Stores a file at the remote server using the GFD.47 (a.k.a GridFTP2) PUT command. Notice that as a side effect this method may change the local server facade passive/active mode setting. The caller should not rely on this setting after call to gridftp2Get. Even though the active/passive status of the current session is ignored for the actual transfer, it still has to be in a consistent state prior to calling gridftp2Get.- Parameters:
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesource
- data will be read from heremListener
- marker listener- Throws:
java.io.IOException
ClientException
ServerException
-
asynchPut2
public TransferState asynchPut2(java.lang.String remoteFileName, boolean passive, DataSource source, MarkerListener mListener) throws java.io.IOException, ClientException, ServerException
Stores a file at the remote server using the GFD.47 (a.k.a GridFTP2) PUT command. Notice that as a side effect this method may change the local server facade passive/active mode setting. The caller should not rely on this setting after call to gridftp2Get. Even though the active/passive status of the current session is ignored for the actual transfer, it still has to be in a consistent state prior to calling gridftp2Get.- Parameters:
remoteFileName
- file to retrievepassive
- whether to configure the server to be passivesource
- data will be read from heremListener
- marker listener- Throws:
java.io.IOException
ClientException
ServerException
-
transfer
public static void transfer(FTPClient source, java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, int mode, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
Performs third-party transfer between two servers. If possibly, GFD.47 (a.k.a GridFTP2) GET and PUT commands are used.- Parameters:
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.- Throws:
java.io.IOException
ServerException
ClientException
-
isActiveMode
public boolean isActiveMode()
-
setUseAllo
public void setUseAllo(boolean useAllo)
Controls whether the client attempts to send an ALLO command before a STOR request during the put/asyncPut calls. This is disabled by default in the FTP client and enabled by default in the GridFTP client. This setting will apply to all subsequent transfers.- Parameters:
useAllo
-true
if the client should try to send an ALLO command before a STOR request
-
getUseAllo
public boolean getUseAllo()
Determines whether this client is configured to send an ALLO command before a STOR request in the put/asyncPut methods.
-
getSupportedCksumAlgorithms
public java.util.List<java.lang.String> getSupportedCksumAlgorithms() throws ClientException, ServerException, java.io.IOException
According to GridFTP v2 Protocol Description checksum feature has the following syntax:CKSUM <algorithm>[, …]
getSupportedCksumAlgorithms parses checsum feauture parms and form a list of checksum algorithms supported by the server- Returns:
- a list of checksum algorithms supported by the server in the order specified by the server
- Throws:
ClientException
ServerException
java.io.IOException
-
isCksumAlgorithmSupported
public boolean isCksumAlgorithmSupported(java.lang.String algorithm) throws ClientException, ServerException, java.io.IOException
- Throws:
ClientException
ServerException
java.io.IOException
-
getChecksum
public java.lang.String getChecksum(java.lang.String algorithm, long offset, long length, java.lang.String path) throws ClientException, ServerException, java.io.IOException
implement GridFTP v2 CKSM command from GridFTP v2 Protocol Description5.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: CKSM <algorithm> <offset> <length> <path> CRLF 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 <checksum value> Actual format of checksum value depends on the algorithm used, but generally, hexadecimal representation should be used.
- Parameters:
algorithm
- ckeckum alorithmoffset
-length
-path
-- Returns:
- ckecksum value returned by the server
- Throws:
ClientException
ServerException
java.io.IOException
-
getChecksum
public java.lang.String getChecksum(java.lang.String algorithm, java.lang.String path) throws ClientException, ServerException, java.io.IOException
GridFTP v2 CKSM command for the whole file- Parameters:
algorithm
- ckeckum alorithmpath
-- Returns:
- ckecksum value returned by the server
- Throws:
ClientException
ServerException
java.io.IOException
-
setChecksum
public void setChecksum(java.lang.String algorithm, java.lang.String value) throws ClientException, ServerException, java.io.IOException
implement GridFTP v2 SCKS command as described in GridFTP v2 Protocol Description5.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: SCKS <algorithm> <value> CRLF Actual format of checksum value depends on the algorithm used, but generally, hexadecimal representation should be used.
- Parameters:
algorithm
-value
-- Throws:
ClientException
ServerException
java.io.IOException
-
-