FTPClient (Java Globus API)

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.


Field Summary
protected  FTPControlChannel controlChannel
           
protected  java.text.SimpleDateFormat dateFormat
           
protected  FTPServerFacade localServer
           
protected  Session session
           
 
Constructor Summary
protected FTPClient()
           
  FTPClient(java.lang.String host, int port)
          Constructs client and connects it to the remote server.
 
Method Summary
 void abort()
          Aborts the current transfer.
protected  void actualGet(java.lang.String remoteFileName, DataSink sink, MarkerListener mListener)
           
protected  void actualList(java.lang.String filter, java.lang.String modifier, DataSink sink)
           
protected  void actualPut(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)
           
protected  void actualSetMode(int mode, java.lang.String modeStr)
           
 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.
 void close()
          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, DataSink sink, MarkerListener mListener)
          Retrieves the file from the remote server.
 java.lang.String getCurrentDir()
          Returns remote current working directory.
 FeatureList getFeatureList()
          Returns list of features supported by remote server.
 java.util.Date getLastModified(java.lang.String filename)
          Returns last modification time of the specifed file.
 long getSize(java.lang.String filename)
          Returns the remote file size.
 void goUpDir()
          Changes remote current working directory to the higher level.
 boolean isFeatureSupported(java.lang.String feature)
          Returns true if the given feature is supported by remote server, false otherwise.
 java.util.Vector list()
          Performs remote directory listing.
 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.
 void put(java.lang.String remoteFileName, DataSource source, MarkerListener mListener)
          Stores file at the remote 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 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 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 transfer(java.lang.String remoteSrcFile, FTPClient destination, java.lang.String remoteDstFile, boolean append, MarkerListener mListener)
          Performs third-party transfer between two servers.
protected  void transferRun(BasicClientControlChannel other, MarkerListener mListener)
          Actual transfer management.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected Session session

controlChannel

protected FTPControlChannel controlChannel

localServer

protected FTPServerFacade localServer

dateFormat

protected java.text.SimpleDateFormat dateFormat
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 host
port - remote server port
Method Detail

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:
FTPException - if the file does not exist or an error occured.
java.io.IOException
ServerException

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:
FTPException - if the file does not exist or an error occured.
java.io.IOException
ServerException

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.
java.io.IOException
ServerException

changeDir

public void changeDir(java.lang.String dir)
               throws java.io.IOException,
                      ServerException
Changes the remote current working directory.

java.io.IOException
ServerException

deleteDir

public void deleteDir(java.lang.String dir)
               throws java.io.IOException,
                      ServerException
Deletes the remote directory.

java.io.IOException
ServerException

deleteFile

public void deleteFile(java.lang.String filename)
                throws java.io.IOException,
                       ServerException
Deletes the remote file.

java.io.IOException
ServerException

makeDir

public void makeDir(java.lang.String dir)
             throws java.io.IOException,
                    ServerException
Creates remote directory.

java.io.IOException
ServerException

rename

public void rename(java.lang.String oldName,
                   java.lang.String newName)
            throws java.io.IOException,
                   ServerException
Renames remote directory.

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.
java.io.IOException
ServerException

goUpDir

public void goUpDir()
             throws java.io.IOException,
                    ServerException
Changes remote current working directory to the higher level.

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 output. If on remote server 'ls' does accept -d option, this method might fail. Also note that 'ls -d' output might be different on each architecture, in which case the parsing might fail. In that case, you may choose to use the parametrized list().

Returns:
Vector list of FileInfo objects, representing remote files
ServerException
ClientException
java.io.IOException

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.

Parameters:
filter - remote list command file filter, eg. "*"
modifier - remote list command modifier, eg. "-d"
sink - data destination
ServerException
ClientException
java.io.IOException

actualList

protected void actualList(java.lang.String filter,
                          java.lang.String modifier,
                          DataSink sink)
                   throws ServerException,
                          ClientException,
                          java.io.IOException
ServerException
ClientException
java.io.IOException

listCheck

protected void listCheck()
                  throws ClientException
check performed at the beginning of list()

ClientException

setType

public void setType(int type)
             throws java.io.IOException,
                    ServerException
Sets transfer type.

Parameters:
type - requested representation type, should be equal to one of the corresponding public variables defined in Session.
java.io.IOException
ServerException

setMode

public void setMode(int mode)
             throws java.io.IOException,
                    ServerException
Sets transfer mode.

Parameters:
mode - requested transfer mode, should be equal to one of the corresponding public variables defined in Session.
java.io.IOException
ServerException

actualSetMode

protected void actualSetMode(int mode,
                             java.lang.String modeStr)
                      throws java.io.IOException,
                             ServerException
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
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.

java.io.IOException
ServerException

close

public void close()
           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.

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.
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.
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.
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
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.

java.io.IOException
ServerException
ClientException

setLocalActive

public void setLocalActive()
                    throws ClientException,
                           java.io.IOException
Starts local server in active server mode.

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)

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_PORT
queue - max size of queue of awaiting new connection requests
Returns:
the server address
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 miliseconds
waitDelay - polling period

setOptions

public void setOptions(Options opts)
                throws java.io.IOException,
                       ServerException
Sets the supplied options to the server.

java.io.IOException
ServerException

setRestartMarker

public void setRestartMarker(RestartData restartData)
                      throws java.io.IOException,
                             ServerException
Sets restart parameter of the next transfer.

Throws:
FTPException - if the file does not exist or an error occured.
java.io.IOException
ServerException

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 - username
Throws:
ServerException - on server refusal
java.io.IOException

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 name
sink - sink to which the data will be written
mListener - restart marker listener (currently not used)
java.io.IOException
ClientException
ServerException

actualGet

protected void actualGet(java.lang.String remoteFileName,
                         DataSink sink,
                         MarkerListener mListener)
                  throws java.io.IOException,
                         ClientException,
                         ServerException
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 name
source - data will be read from here
mListener - restart marker listener (currently not used)
java.io.IOException
ServerException
ClientException

actualPut

protected void actualPut(java.lang.String remoteFileName,
                         DataSource source,
                         MarkerListener mListener)
                  throws java.io.IOException,
                         ServerException,
                         ClientException
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 filename
remoteDstFile - destination filename
append - 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.
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.

java.io.IOException
ServerException
ClientException