|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
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 hostport- 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.IOExceptionServerException
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.IOExceptionServerException
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.IOExceptionServerException
changeDir
public void changeDir(java.lang.String dir)
throws java.io.IOException,
ServerException
- Changes the remote current working directory.
java.io.IOExceptionServerException
deleteDir
public void deleteDir(java.lang.String dir)
throws java.io.IOException,
ServerException
- Deletes the remote directory.
java.io.IOExceptionServerException
deleteFile
public void deleteFile(java.lang.String filename)
throws java.io.IOException,
ServerException
- Deletes the remote file.
java.io.IOExceptionServerException
makeDir
public void makeDir(java.lang.String dir)
throws java.io.IOException,
ServerException
- Creates remote directory.
java.io.IOExceptionServerException
rename
public void rename(java.lang.String oldName,
java.lang.String newName)
throws java.io.IOException,
ServerException
- Renames remote directory.
java.io.IOExceptionServerException
getCurrentDir
public java.lang.String getCurrentDir()
throws java.io.IOException,
ServerException
- Returns remote current working directory.
- Returns:
- remote current working directory.
java.io.IOExceptionServerException
goUpDir
public void goUpDir()
throws java.io.IOException,
ServerException
- Changes remote current working directory to the higher level.
java.io.IOExceptionServerException
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
ServerExceptionClientExceptionjava.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 destinationServerExceptionClientExceptionjava.io.IOException
actualList
protected void actualList(java.lang.String filter,
java.lang.String modifier,
DataSink sink)
throws ServerException,
ClientException,
java.io.IOException
ServerExceptionClientExceptionjava.io.IOException
listCheck
protected void listCheck()
throws ClientException
- check performed at the beginning of list()
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.IOExceptionServerException
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.IOExceptionServerException
actualSetMode
protected void actualSetMode(int mode,
java.lang.String modeStr)
throws java.io.IOException,
ServerException
java.io.IOExceptionServerException
setProtectionBufferSize
public void setProtectionBufferSize(int size)
throws java.io.IOException,
ServerException
- Sets protection buffer size (defined in RFC 2228)
- Parameters:
size- the size of bufferjava.io.IOExceptionServerException
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.IOExceptionServerException
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.IOExceptionServerException
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.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.
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.
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 connectjava.io.IOExceptionServerException
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.IOExceptionServerExceptionClientException
setLocalActive
public void setLocalActive()
throws ClientException,
java.io.IOException
- Starts local server in active server mode.
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)
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
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.
java.io.IOExceptionServerException
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.IOExceptionServerException
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 refusaljava.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 namesink- sink to which the data will be writtenmListener- restart marker listener (currently not used)java.io.IOExceptionClientExceptionServerException
actualGet
protected void actualGet(java.lang.String remoteFileName,
DataSink sink,
MarkerListener mListener)
throws java.io.IOException,
ClientException,
ServerException
java.io.IOExceptionClientExceptionServerException
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)java.io.IOExceptionServerExceptionClientException
actualPut
protected void actualPut(java.lang.String remoteFileName,
DataSource source,
MarkerListener mListener)
throws java.io.IOException,
ServerException,
ClientException
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,
ClientException
- Performs third-party transfer between two servers.
- Parameters:
remoteSrcFile- source filenameremoteDstFile- 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.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.
java.io.IOExceptionServerExceptionClientException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||