|
ZetaGrid v1.9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--zeta.tool.FTP
Implementation of the File Transfer Protocol. Only the passive mode is implemented for connections, i.e. forces the client to open the data connection to the FTP server which is useful to getting past Firewalls.
| Nested Class Summary | |
private static class |
FTP.Response
Encompasses the FTP server's response - code and message |
| Field Summary | |
private boolean |
abort
|
private boolean |
allowRestart
|
private boolean |
authenticated
|
private int |
bufferSize
Transmit buffer defaults to 10k (binary transfers only) |
private java.io.BufferedReader |
controlInputStream
|
private java.io.PrintStream |
controlOutputStream
|
private java.net.Socket |
controlSocket
|
private java.io.PrintStream |
debug
Printer for debugging statements. |
private java.lang.String |
host
|
static boolean |
MODE_ASCII
Use ASCII mode (attempt to handle new-line's in a sane manner) |
static boolean |
MODE_BINARY
Use binary mode - no translation is performed. |
private int |
socketTimeout
Network socket timeout. |
private int |
transferSleep
|
| Constructor Summary | |
FTP()
|
|
| Method Summary | |
void |
abort()
Attempt to gracefully abort active transfer. |
void |
cd(java.lang.String newDir)
Switches current directory on the FTP server. |
private void |
checkConnection(java.lang.String command)
Checks whether the FTP connection has been authenticated. |
private FTP.Response |
checkResponseCode(java.lang.String command)
Convinience routine to simplify the creation of exceptions |
void |
close()
Closes the control connection to the FTP server. |
void |
connect(java.lang.String host)
Connect to the specified host using standard FTP port (21). |
void |
connect(java.lang.String host,
int port)
Connect to the specified host using standard FTP port (21) The default network socket timeout is 50 milliseconds. |
void |
deleteDir(java.lang.String dirName)
Removes a directory on the FTP server. |
void |
deleteFile(java.lang.String fileName)
Removes a specified file on the FTP server. |
java.util.List |
dir()
Retrieves the file list in the current working directory on the FTP server. |
void |
disconnect()
Closes the control connection to the FTP server. |
private FTP.Response |
executeCommand(java.lang.String commandName,
java.lang.String arguments)
Executes an FTP command and checks the response |
void |
get(java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode)
Downloads the specified remote file from FTP server in the output stream using the specified mode. |
void |
get(java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode,
long startAt)
Downloads the specified remote file from FTP server in the output stream using the specified mode, starting at the specified position (byte). |
void |
get(java.lang.String remoteFile,
java.lang.String localFile,
boolean mode)
Downloads the specified remote file from FTP server to the local file using the specified mode. |
void |
get(java.lang.String remoteDir,
java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode,
long startAt)
Downloads the specified remote file residing in the remote directory from FTP server in the output stream using the specified mode, starting at the specified position (byte). |
void |
get(java.lang.String remoteDir,
java.lang.String remoteFile,
java.lang.String localFile,
boolean mode)
Downloads the specified remote file residing in the remote directory from FTP server to the local file using the specified mode. |
int |
getBufferSize()
Returns the current send/receive buffer size for binary transfers. |
private java.net.Socket |
getDataSocket(java.lang.String command)
Creates a passive socket and executes the specified command. |
java.lang.String |
getHost()
Returns the host name of the FTP server. |
int |
getSocketTimeout()
Returns the current socket timeout in milliseconds. |
boolean |
isAllowRestart()
Returns true if code attempts to restart downloads,
false if existing files are overwritten.
|
boolean |
isDebug()
Returns current debug state. |
void |
login(java.lang.String user,
java.lang.String password)
Authenticate with the FTP server which is required for most operations. |
java.util.List |
longDir()
Retrieves the extended file list in the current working directory on the FTP server. |
static void |
main(java.lang.String[] args)
Simple test program. |
void |
makeDir(java.lang.String newDir)
Creates a directory on the FTP server. |
void |
put(java.io.InputStream in,
java.lang.String remoteFile,
boolean mode)
Uploads the contents of the specified input stream to the remote file (in current remote directory of the FTP server) using the specified mode. |
void |
put(java.io.InputStream in,
java.lang.String remoteDir,
java.lang.String remoteFile,
boolean mode)
Uploads the contents of the specified input stream to the remote file in the remote directory of the FTP server using the specified mode. |
void |
put(java.lang.String localFile,
java.lang.String remoteFile,
boolean mode)
Uploads the specified local file to the remote file (in current remote directory of the FTP server) using the specified mode. |
void |
put(java.lang.String localFile,
java.lang.String remoteDir,
java.lang.String remoteFile,
boolean mode)
Uploads the specified local file to the remote file in the remote directory of the FTP server using the specified mode. |
java.lang.String |
pwd()
Returns the current working directory as seen by the FTP server. |
java.lang.String |
quote(java.lang.String param)
Executes an arbitrary command on the FTP server. |
void |
rename(java.lang.String oldName,
java.lang.String newName)
Renames a specified file on the FTP server. |
void |
setAllowRestart(boolean allowRestart)
Allow the library to automatically restart downloads. |
void |
setBufferSize(int size)
Set the send/receive buffer size for binary transfers. |
void |
setDebug(java.io.PrintStream debug)
Enable or disable debugging. |
void |
setMode(boolean mode)
Switches the transfer mode. |
void |
setSocketTimeout(int timeout)
Sets the network socket timeout in milliseconds. |
void |
setTransferSleep(int millis)
Causes the currently executing thread to sleep for the specified number of milliseconds after during each send/receive. |
java.lang.String |
site(java.lang.String siteCmd)
Executes a SITE command on the FTP server. |
java.lang.String |
systemID()
Returns the System ID as supplied by the FTP server. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final boolean MODE_ASCII
public static final boolean MODE_BINARY
private int socketTimeout
private java.io.PrintStream debug
private int bufferSize
private int transferSleep
private boolean allowRestart
private java.lang.String host
private java.net.Socket controlSocket
private java.io.BufferedReader controlInputStream
private java.io.PrintStream controlOutputStream
private boolean authenticated
private boolean abort
| Constructor Detail |
public FTP()
| Method Detail |
public void connect(java.lang.String host)
throws java.io.IOException
host - host name of the FTP server
java.io.IOException - if an I/O error occurs.
public void connect(java.lang.String host,
int port)
throws java.io.IOException
host - host name of the FTP serverport - port number of the FTP server
java.io.IOException - if an I/O error occurs.
public void login(java.lang.String user,
java.lang.String password)
throws java.io.IOException
java.io.IOException
public void abort()
throws java.io.IOException
java.io.IOExceptionpublic void close()
public void disconnect()
public void setMode(boolean mode)
throws java.io.IOException
MODE_ASCII and MODE_BINARY.
ASCII mode attempts to convert newlines to a format understandable by the target system.
This works for text files, but corrupts data files.
Binary mode ensures that the file is transferred "as-is."
For transfers between like-systems this is the preferred mode, as it is much faster.
java.io.IOException
public void get(java.lang.String remoteFile,
java.lang.String localFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The remote file must be in the current directory, or the full path must be given.
java.io.IOException
public void get(java.lang.String remoteDir,
java.lang.String remoteFile,
java.lang.String localFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
java.io.IOException
public void get(java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The remote file must be in the current directory, or the full path must be given.
java.io.IOException
public void get(java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode,
long startAt)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The remote file must be in the current directory, or the full path must be given.
java.io.IOException
public void get(java.lang.String remoteDir,
java.lang.String remoteFile,
java.io.OutputStream output,
boolean mode,
long startAt)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The remote file must be in the current directory, or the full path must be given.
java.io.IOException
public void put(java.lang.String localFile,
java.lang.String remoteFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The local file should include a fully qualified path.
java.io.IOException
public void put(java.lang.String localFile,
java.lang.String remoteDir,
java.lang.String remoteFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
The local file should include a fully qualified path.
java.io.IOException
public void put(java.io.InputStream in,
java.lang.String remoteFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
java.io.IOException
public void put(java.io.InputStream in,
java.lang.String remoteDir,
java.lang.String remoteFile,
boolean mode)
throws java.io.IOException
MODE_ASCII or MODE_BINARY.
java.io.IOException
public java.util.List dir()
throws java.io.IOException
java.io.IOException
public java.util.List longDir()
throws java.io.IOException
java.io.IOException
public java.lang.String systemID()
throws java.io.IOException
java.io.IOException
public void cd(java.lang.String newDir)
throws java.io.IOException
java.io.IOException
public void makeDir(java.lang.String newDir)
throws java.io.IOException
java.io.IOException
public java.lang.String pwd()
throws java.io.IOException
java.io.IOException
public void rename(java.lang.String oldName,
java.lang.String newName)
throws java.io.IOException
java.io.IOException
public void deleteDir(java.lang.String dirName)
throws java.io.IOException
java.io.IOException
public void deleteFile(java.lang.String fileName)
throws java.io.IOException
java.io.IOException
public java.lang.String quote(java.lang.String param)
throws java.io.IOException
java.io.IOException
public java.lang.String site(java.lang.String siteCmd)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getHost()
public void setBufferSize(int size)
public int getBufferSize()
public void setTransferSleep(int millis)
public void setSocketTimeout(int timeout)
public int getSocketTimeout()
public void setAllowRestart(boolean allowRestart)
true>, the libarary will check the existing
file size, and re-start the download at that point.
This feature does not take into account corrupted data, etc.
The default setting of false means that existing files
will get overwritten.
Note that this has no effect on downloads to streams.
public boolean isAllowRestart()
true if code attempts to restart downloads,
false if existing files are overwritten.
By default the library will overwrite existing files.
Note that this has no effect on downloads to streams.
public void setDebug(java.io.PrintStream debug)
public boolean isDebug()
private void checkConnection(java.lang.String command)
throws java.io.IOException
java.io.IOException
private FTP.Response checkResponseCode(java.lang.String command)
throws java.io.IOException
java.io.IOException
private FTP.Response executeCommand(java.lang.String commandName,
java.lang.String arguments)
throws java.io.IOException
java.io.IOException
private java.net.Socket getDataSocket(java.lang.String command)
throws java.io.IOException
java.io.IOExceptionpublic static void main(java.lang.String[] args)
|
ZetaGrid v1.9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||