Package org.globus.ftp
Class FTPClient
- java.lang.Object
-
- org.globus.ftp.FTPClient
-
- Direct Known Subclasses:
GridFTPClient
public class FTPClient extends java.lang.ObjectThis 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>algorithmsList of the checksum algorithms supported by the server as described in GridFTP v2 Protocol Descriptionprotected FTPControlChannelcontrolChannelprotected java.text.SimpleDateFormatdateFormatprotected FTPServerFacadelocalServerstatic java.util.regex.PatternportPatternRegular expression for matching the port information of a GFD.47 127 reply.protected Sessionsessionprotected booleanuseAlloWhether to use ALLO with put()/asyncPut() or notprotected java.lang.Stringusername
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Aborts the current transfer.protected voidactualSetMode(int mode, java.lang.String modeStr)voidallocate(long size)Reserve sufficient storage to accommodate the new file to be transferred.TransferStateasynchGet(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener)Retrieves the file from the remote server.TransferStateasynchGet2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener)Retrieves a file asynchronously using the GFD.47 (a.k.a GridFTP2) GET command.TransferStateasynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)Stores file at the remote server.TransferStateasynchPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append)Stores file at the remote server.TransferStateasynchPut2(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.voidauthorize(java.lang.String user, java.lang.String password)Performs user authorization with specified user and password.voidchangeDir(java.lang.String dir)Changes the remote current working directory.protected voidcheckGETPUTSupport()Throws ServerException if GFD.47 GETPUT is not supported or cannot be used.protected voidcheckTransferParams()protected voidcheckTransferParamsGet()protected voidcheckTransferParamsPut()voidclose()Closes connection.voidclose(boolean ignoreQuitReply)Closes connection.voiddeleteDir(java.lang.String dir)Deletes the remote directory.voiddeleteFile(java.lang.String filename)Deletes the remote file.booleanexists(java.lang.String filename)Checks if given file/directory exists on the server.voidget(java.lang.String remoteFileName, java.io.File localFile)voidget(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener)Retrieves the file from the remote server.protected HostPortget127Reply()Reads a GFD.47 compliant 127 reply and extracts the port information from it.voidget2(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.StringgetChecksum(java.lang.String algorithm, long offset, long length, java.lang.String path)implement GridFTP v2 CKSM command from GridFTP v2 Protocol Descriptionjava.lang.StringgetChecksum(java.lang.String algorithm, java.lang.String path)GridFTP v2 CKSM command for the whole filejava.lang.StringgetCurrentDir()Returns remote current working directory.FeatureListgetFeatureList()Returns list of features supported by remote server.java.lang.StringgetHost()java.util.DategetLastModified(java.lang.String filename)Returns last modification time of the specifed file.ReplygetLastReply()Returns the last reply received from the server.protected java.lang.StringgetModeStr(int mode)intgetPort()longgetSize(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:booleangetUseAllo()Determines whether this client is configured to send an ALLO command before a STOR request in the put/asyncPut methods.java.lang.StringgetUserName()voidgoUpDir()Changes remote current working directory to the higher level.booleanisActiveMode()booleanisCksumAlgorithmSupported(java.lang.String algorithm)booleanisFeatureSupported(java.lang.String feature)Returns true if the given feature is supported by remote server, false otherwise.booleanisPassiveMode()java.util.DatelastModified(java.lang.String filename)java.util.Vectorlist()Performs remote directory listing.java.util.Vectorlist(java.lang.String filter)Performs remote directory listing with the specified filter.java.util.Vectorlist(java.lang.String filter, java.lang.String modifier)Performs remote directory listing with the specified filter and modifier.voidlist(java.lang.String filter, java.lang.String modifier, DataSink sink)Performs directory listing and writes the result to the supplied data sink.protected voidlistCheck()check performed at the beginning of list()voidmakeDir(java.lang.String dir)Creates remote directory.java.util.Vectormlsd()Performs remote directory listing of the current directory.java.util.Vectormlsd(java.lang.String path)Performs remote directory listing on the given path.voidmlsd(java.lang.String path, DataSink sink)Performs remote directory listing on the given path.MlsxEntrymlst(java.lang.String fileName)Get info of a certain remote file in Mlsx format.java.util.Vectornlist()Performs remote directory listing of the current directory.java.util.Vectornlist(java.lang.String path)Performs remote directory listing on the given path.voidnlist(java.lang.String path, DataSink sink)Performs remote directory listing on the given path.protected voidperformTransfer(Command cmd, DataSink sink)voidput(java.io.File localFile, java.lang.String remoteFileName, boolean append)voidput(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)Stores file at the remote server.voidput(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append)Stores file at the remote server.voidput2(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.Replyquote(java.lang.String command)Executes arbitrary operation on the server.voidrename(java.lang.String oldName, java.lang.String newName)Renames remote directory.voidsetActive()Sets remote server active, telling it to connect to the client.voidsetActive(HostPort hostPort)Sets remote server active, telling it to connect to the given address.voidsetChecksum(java.lang.String algorithm, java.lang.String value)implement GridFTP v2 SCKS command as described in GridFTP v2 Protocol DescriptionvoidsetClientWaitParams(int maxWait, int waitDelay)Changes the default client timeout parameters.voidsetLocalActive()Starts local server in active server mode.HostPortsetLocalPassive()Starts local server in passive server mode, with default parameters.HostPortsetLocalPassive(int port, int queue)Starts the local server in passive server mode.voidsetMode(int mode)Sets transfer mode.voidsetOptions(Options opts)Sets the supplied options to the server.HostPortsetPassive()Sets remote server to passive server mode.voidsetPassiveMode(boolean passiveMode)Enables/disables passive data connections.voidsetProtectionBufferSize(int size)Sets protection buffer size (defined in RFC 2228)voidsetRestartMarker(RestartData restartData)Sets restart parameter of the next transfer.voidsetType(int type)Sets transfer type.voidsetUseAllo(boolean useAllo)Controls whether the client attempts to send an ALLO command before a STOR request during the put/asyncPut calls.Replysite(java.lang.String args)Executes site-specific operation (using the SITE command).longsize(java.lang.String filename)voidtransfer(java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, boolean append, MarkerListener mListener)Performs third-party transfer between two servers.static voidtransfer(FTPClient source, java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, int mode, MarkerListener mListener)Performs third-party transfer between two servers.protected TransferStatetransferBegin(BasicClientControlChannel other, MarkerListener mListener)protected voidtransferRun(BasicClientControlChannel other, MarkerListener mListener)Actual transfer management.protected voidtransferRunSingleThread(BasicClientControlChannel other, MarkerListener mListener)protected TransferStatetransferStart(BasicClientControlChannel other, MarkerListener mListener)protected voidtransferWait(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, ServerExceptionConstructs client and connects it to the remote server.- Parameters:
host- remote server hostport- remote server port- Throws:
java.io.IOExceptionServerException
-
-
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, ServerExceptionReturns 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, ServerExceptionReturns 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, ServerExceptionChecks 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.IOExceptionServerException
-
changeDir
public void changeDir(java.lang.String dir) throws java.io.IOException, ServerExceptionChanges the remote current working directory.- Throws:
java.io.IOExceptionServerException
-
deleteDir
public void deleteDir(java.lang.String dir) throws java.io.IOException, ServerExceptionDeletes the remote directory.- Throws:
java.io.IOExceptionServerException
-
deleteFile
public void deleteFile(java.lang.String filename) throws java.io.IOException, ServerExceptionDeletes the remote file.- Throws:
java.io.IOExceptionServerException
-
makeDir
public void makeDir(java.lang.String dir) throws java.io.IOException, ServerExceptionCreates remote directory.- Throws:
java.io.IOExceptionServerException
-
rename
public void rename(java.lang.String oldName, java.lang.String newName) throws java.io.IOException, ServerExceptionRenames remote directory.- Throws:
java.io.IOExceptionServerException
-
getCurrentDir
public java.lang.String getCurrentDir() throws java.io.IOException, ServerExceptionReturns remote current working directory.- Returns:
- remote current working directory.
- Throws:
java.io.IOExceptionServerException
-
goUpDir
public void goUpDir() throws java.io.IOException, ServerExceptionChanges remote current working directory to the higher level.- Throws:
java.io.IOExceptionServerException
-
list
public java.util.Vector list() throws ServerException, ClientException, java.io.IOExceptionPerforms 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
FileInfoobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.io.IOException- See Also:
mlsd()
-
list
public java.util.Vector list(java.lang.String filter) throws ServerException, ClientException, java.io.IOExceptionPerforms 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
FileInfoobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.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.IOExceptionPerforms 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
FileInfoobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.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.IOExceptionPerforms 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:
ServerExceptionClientExceptionjava.io.IOException
-
nlist
public java.util.Vector nlist() throws ServerException, ClientException, java.io.IOExceptionPerforms remote directory listing of the current directory. Sends 'NLST' command.- Returns:
- Vector list of
FileInfoobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.io.IOException
-
nlist
public java.util.Vector nlist(java.lang.String path) throws ServerException, ClientException, java.io.IOExceptionPerforms 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
FileInfoobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.io.IOException
-
nlist
public void nlist(java.lang.String path, DataSink sink) throws ServerException, ClientException, java.io.IOExceptionPerforms 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:
ServerExceptionClientExceptionjava.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.IOExceptionServerException
-
mlsd
public java.util.Vector mlsd() throws ServerException, ClientException, java.io.IOExceptionPerforms remote directory listing of the current directory. Sends 'MLSD' command.- Returns:
- Vector list of
MlsxEntryobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.io.IOException
-
mlsd
public java.util.Vector mlsd(java.lang.String path) throws ServerException, ClientException, java.io.IOExceptionPerforms 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
MlsxEntryobjects, representing remote files - Throws:
ServerExceptionClientExceptionjava.io.IOException
-
mlsd
public void mlsd(java.lang.String path, DataSink sink) throws ServerException, ClientException, java.io.IOExceptionPerforms 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:
ServerExceptionClientExceptionjava.io.IOException
-
listCheck
protected void listCheck() throws ClientExceptioncheck performed at the beginning of list()- Throws:
ClientException
-
checkTransferParamsGet
protected void checkTransferParamsGet() throws ServerException, java.io.IOException, ClientException- Throws:
ServerExceptionjava.io.IOExceptionClientException
-
checkTransferParamsPut
protected void checkTransferParamsPut() throws ServerException, java.io.IOException, ClientException- Throws:
ServerExceptionjava.io.IOExceptionClientException
-
checkTransferParams
protected void checkTransferParams() throws ServerException, java.io.IOException, ClientException- Throws:
ServerExceptionjava.io.IOExceptionClientException
-
performTransfer
protected void performTransfer(Command cmd, DataSink sink) throws ServerException, ClientException, java.io.IOException
- Throws:
ServerExceptionClientExceptionjava.io.IOException
-
setType
public void setType(int type) throws java.io.IOException, ServerExceptionSets transfer type.- Parameters:
type- should beTYPE_IMAGE,TYPE_ASCII,TYPE_LOCAL,TYPE_EBCDIC- Throws:
java.io.IOExceptionServerException
-
getModeStr
protected java.lang.String getModeStr(int mode)
-
setMode
public void setMode(int mode) throws java.io.IOException, ServerExceptionSets transfer mode.- Parameters:
mode- should beMODE_STREAM,MODE_BLOCK- Throws:
java.io.IOExceptionServerException
-
actualSetMode
protected void actualSetMode(int mode, java.lang.String modeStr) throws java.io.IOException, ServerException- Throws:
java.io.IOExceptionServerException
-
setProtectionBufferSize
public void setProtectionBufferSize(int size) throws java.io.IOException, ServerExceptionSets protection buffer size (defined in RFC 2228)- Parameters:
size- the size of buffer- Throws:
java.io.IOExceptionServerException
-
abort
public void abort() throws java.io.IOException, ServerExceptionAborts 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.IOExceptionServerException
-
close
public void close() throws java.io.IOException, ServerExceptionCloses 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.IOExceptionServerException
-
close
public void close(boolean ignoreQuitReply) throws java.io.IOException, ServerExceptionCloses connection. Sends QUIT and closes connection even if the server reply was not positive. Also, closes the local server.- Parameters:
ignoreQuitReply- if true theQUITcommand 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.IOExceptionServerException
-
isFeatureSupported
public boolean isFeatureSupported(java.lang.String feature) throws java.io.IOException, ServerExceptionReturns 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.IOExceptionServerException
-
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.IOExceptionServerException
-
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.IOExceptionServerException
-
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.IOExceptionServerException
-
setActive
public void setActive() throws java.io.IOException, ServerException, ClientExceptionSets remote server active, telling it to connect to the client. setLocalPassive() must be called beforehand.- Throws:
java.io.IOExceptionServerExceptionClientException
-
setLocalActive
public void setLocalActive() throws ClientException, java.io.IOExceptionStarts local server in active server mode.- Throws:
ClientExceptionjava.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.IOExceptionServerException
-
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, ServerExceptionPerforms 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, ServerExceptionRetrieves 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.IOExceptionClientExceptionServerException
-
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.IOExceptionClientExceptionServerException
-
put
public void put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener) throws java.io.IOException, ServerException, ClientExceptionStores 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.IOExceptionServerExceptionClientException
-
put
public void put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener, boolean append) throws java.io.IOException, ServerException, ClientExceptionStores 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.IOExceptionServerExceptionClientException
-
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.IOExceptionServerExceptionClientException
-
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.IOExceptionServerExceptionClientException
-
transfer
public void transfer(java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, boolean append, MarkerListener mListener) throws java.io.IOException, ServerException, ClientExceptionPerforms 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.IOExceptionServerExceptionClientException
-
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.IOExceptionServerExceptionClientException
-
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.IOExceptionServerExceptionClientException
-
transferWait
protected void transferWait(TransferState transferState) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOExceptionServerExceptionClientException
-
transferRunSingleThread
protected void transferRunSingleThread(BasicClientControlChannel other, MarkerListener mListener) throws java.io.IOException, ServerException, ClientException
- Throws:
java.io.IOExceptionServerExceptionClientException
-
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, ServerExceptionReserve 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.IOExceptionServerException
-
lastModified
public java.util.Date lastModified(java.lang.String filename) throws java.io.IOException, ServerException- Throws:
java.io.IOExceptionServerException
-
get
public void get(java.lang.String remoteFileName, java.io.File localFile) throws java.io.IOException, ClientException, ServerException- Throws:
java.io.IOExceptionClientExceptionServerException
-
put
public void put(java.io.File localFile, java.lang.String remoteFileName, boolean append) throws java.io.IOException, ServerException, ClientException- Throws:
java.io.IOExceptionServerExceptionClientException
-
setPassiveMode
public void setPassiveMode(boolean passiveMode) throws java.io.IOException, ClientException, ServerExceptionEnables/disables passive data connections.- Parameters:
passiveMode- if true passive connections will be established. If false, they will not.- Throws:
java.io.IOExceptionClientExceptionServerException
-
isPassiveMode
public boolean isPassiveMode()
-
checkGETPUTSupport
protected void checkGETPUTSupport() throws ServerException, java.io.IOExceptionThrows ServerException if GFD.47 GETPUT is not supported or cannot be used.- Throws:
ServerExceptionjava.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:
ServerExceptionjava.io.IOExceptionFTPReplyParseException
-
get2
public void get2(java.lang.String remoteFileName, boolean passive, DataSink sink, MarkerListener mListener) throws java.io.IOException, ClientException, ServerExceptionRetrieves 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.IOExceptionClientExceptionServerException
-
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.IOExceptionClientExceptionServerException
-
put2
public void put2(java.lang.String remoteFileName, boolean passive, DataSource source, MarkerListener mListener) throws java.io.IOException, ClientException, ServerExceptionStores 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.IOExceptionClientExceptionServerException
-
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.IOExceptionClientExceptionServerException
-
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.IOExceptionServerExceptionClientException
-
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-trueif 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.IOExceptionAccording 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:
ClientExceptionServerExceptionjava.io.IOException
-
isCksumAlgorithmSupported
public boolean isCksumAlgorithmSupported(java.lang.String algorithm) throws ClientException, ServerException, java.io.IOException- Throws:
ClientExceptionServerExceptionjava.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.IOExceptionimplement 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:
ClientExceptionServerExceptionjava.io.IOException
-
getChecksum
public java.lang.String getChecksum(java.lang.String algorithm, java.lang.String path) throws ClientException, ServerException, java.io.IOExceptionGridFTP v2 CKSM command for the whole file- Parameters:
algorithm- ckeckum alorithmpath-- Returns:
- ckecksum value returned by the server
- Throws:
ClientExceptionServerExceptionjava.io.IOException
-
setChecksum
public void setChecksum(java.lang.String algorithm, java.lang.String value) throws ClientException, ServerException, java.io.IOExceptionimplement 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:
ClientExceptionServerExceptionjava.io.IOException
-
-