|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--gnu.inet.ftp.FtpClientProtocol
This is the core implementation of the FTP client protocol, RFC0959. You should be able to find the document via searches on the World Wide Web. At the time of this writing, RFCs could be found at www.faqs.org.
The purpose of this class is to implement the FTP client protocol as simply and straight-forward as possible.
This package was started as an implementation of the HylaFAX client protocol so the features that overlap with the HylaFAX protocol will be the first implemented and most tested.
Method names are not my choosing for the most part. They have been largely pulled straight from the protocol and man pages. I expect that convenience classes and methods, with more developer friendly names will be built on top of this raw protocol implementation as time passes.
Most developers should use the higher-level FtpClient to perform some actions rather than this class directly.
| Field Summary | |
static int |
DEFAULT_PORT
default FTP server port. |
protected char |
fileType
|
protected java.lang.String |
greeting
|
protected java.io.BufferedReader |
istream
|
static java.lang.String |
MDTM_TIME_FORMAT1
|
static java.lang.String |
MDTM_TIME_FORMAT2
|
static char |
MODE_BLOCK
data transfer mode is BLOCK mode |
static char |
MODE_COMPRESSED
data transfer mode is COMPRESSED, as in UNIX compress. |
static char |
MODE_STREAM
data transfer mode is STREAM |
static char |
MODE_ZLIB
data transfer mode is ZLIB, as in zlib compression. |
protected java.io.OutputStreamWriter |
ostream
|
protected int |
port
|
protected java.net.Socket |
sock
|
static char |
STRU_FILE
the file structure is FILE. |
static char |
STRU_PAGE
the file structure is PAGE based. |
static char |
STRU_RECORD
the file structure is RECORD based. |
static char |
STRU_TIFF
the file structure is TIFF. |
static char |
TYPE_ASCII
the file type is ASCII |
static char |
TYPE_EBCDIC
the file type is EBCDIC |
static char |
TYPE_IMAGE
the file type is an 'image'. |
static char |
TYPE_LOCAL
the file type is a local type |
| Constructor Summary | |
FtpClientProtocol()
default constructor. |
|
| Method Summary | |
void |
abor()
abort the last command |
void |
abor(java.lang.String modem)
abort the last command on the given modem. |
void |
cdup()
change to parent of current working directory |
protected void |
connect(java.lang.String host,
int portnumber)
connect to the given host at the given port number. |
void |
cwd(java.lang.String value)
change current working directory |
void |
dele(java.lang.String pathname)
delete the given file. |
boolean |
getDebug()
Returns true if ConsoleLogger is in debug mode. |
java.lang.String |
getGreeting()
|
java.net.InetAddress |
getInetAddress()
get the local ip address of the control connection socket. |
char |
getType()
Return the file type for transfer. |
long |
idle()
get the current idle timeout in seconds |
void |
idle(long timeout)
set the idle timeout value to the given number of seconds |
void |
list()
get list of files in current directory. |
void |
list(java.lang.String path)
get a list of files in a directory. |
java.util.Date |
mdtm(java.lang.String pathname)
Returns the last modified time of the given file. |
void |
mode(char value)
set the data transfer mode. |
void |
nlst()
get name list of files in directory. |
void |
nlst(java.lang.String path)
get name list of files in directory. |
void |
noop()
perform server No Operation could be used as a keep-alive |
void |
open()
open a connection to the localhost on the default port |
void |
open(java.lang.String host)
open a connection to a given server at default port this is an alias for connect() |
void |
open(java.lang.String host,
int portnumber)
open a connection to a given server and port this is an alias for connect() |
void |
pass(java.lang.String password)
send the password for this username and session |
PassiveParameters |
pasv()
prepare for server-to-server transfer (passive mode) |
void |
port(java.net.InetAddress address,
int port)
tell the server which address/port we will listen on |
java.lang.String |
pwd()
return current directory |
void |
quit()
end session |
protected java.lang.String |
readResponse(java.io.BufferedReader input)
read a (multi-line) response |
void |
retr(java.lang.String path)
retrieve the given file |
void |
rnfr(java.lang.String pathname)
Specifies a file to be renamed. |
void |
rnto(java.lang.String pathname)
Renames a previously specified file to the given name. |
void |
setDebug(boolean value)
Sets the ConsoleLogger's debug output. |
long |
size(java.lang.String pathname)
Returns the size (in bytes) of the given regular file. |
java.util.Vector |
stat()
Returns the server status message. |
java.util.Vector |
stat(java.lang.String path)
Returns the status of the named file or directory. |
void |
stor(java.io.InputStream in,
java.lang.String pathname)
store a file. |
java.lang.String |
stot(java.io.InputStream data)
store temp file, the file is stored in a uniquely named file on the server. |
java.lang.String |
stou(java.io.InputStream in)
store a file with a unique name. |
void |
stru(char value)
set the file structure. |
java.lang.String |
syst()
get system type returns the string that the server sends (not sure how to handle it yet) on a Debian GNU/Linux 2.1 (slink) system, the result string is: "UNIX Type: L8 Version: SVR4" |
void |
type(char value)
Set the file type for transfer. |
boolean |
user(java.lang.String username)
send the user name for this session |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.net.Socket sock
protected int port
protected java.io.BufferedReader istream
protected java.io.OutputStreamWriter ostream
protected java.lang.String greeting
protected char fileType
public static int DEFAULT_PORT
public static final char TYPE_ASCII
public static final char TYPE_EBCDIC
public static final char TYPE_IMAGE
public static final char TYPE_LOCAL
public static final char MODE_STREAM
public static final char MODE_BLOCK
public static final char MODE_COMPRESSED
public static final char MODE_ZLIB
public static final char STRU_FILE
public static final char STRU_RECORD
public static final char STRU_PAGE
public static final char STRU_TIFF
public static final java.lang.String MDTM_TIME_FORMAT1
public static final java.lang.String MDTM_TIME_FORMAT2
| Constructor Detail |
public FtpClientProtocol()
| Method Detail |
public java.net.InetAddress getInetAddress()
public void open(java.lang.String host,
int portnumber)
throws java.net.UnknownHostException,
java.io.IOException,
ServerResponseException
host - the hostname of the HylaFAX serverportnumber - the port the server is listening onjava.net.UnknownHostException - cannot resolve the given hostnamejava.io.IOException - IO error occurredServerResponseException - the server replied with an error code
public void open(java.lang.String host)
throws java.net.UnknownHostException,
java.io.IOException,
ServerResponseException
host - the hostname of the HylaFAX serverjava.net.UnknownHostException - cannot resolve the given hostnamejava.io.IOException - IO error occurredServerResponseException - the server replied with an error code
public void open()
throws java.net.UnknownHostException,
java.io.IOException,
ServerResponseException
java.net.UnknownHostException - cannot resolve the given hostnamejava.io.IOException - IO error occurredServerResponseException - the server replied with an error code
public boolean user(java.lang.String username)
throws java.io.IOException,
ServerResponseException
username - name of the user to login asjava.io.IOException - io error occurredServerResponseException - server replied with an error code
public void pass(java.lang.String password)
throws java.io.IOException,
ServerResponseException
password - the password to login withjava.io.IOException - io error occurredServerResponseException - server replied with an error code
public void noop()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error code
public java.lang.String pwd()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error code
public void cwd(java.lang.String value)
throws java.io.IOException,
ServerResponseException
value - directory to set to current working directoryjava.io.IOException - io error occurredServerResponseException - server replied with an error code
public void cdup()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with error code
public long idle()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error code
public void idle(long timeout)
throws java.io.IOException,
ServerResponseException
timeout - new timeout value in seconds (MAX = 7200)java.io.IOException - io error occurredServerResponseException - server replied with an error code
public void dele(java.lang.String pathname)
throws java.io.IOException,
ServerResponseException
pathname - the name of the file to deletejava.io.IOException - a socket IO error happenedServerResponseException - the server replied with an error code
public void type(char value)
throws java.io.IOException,
ServerResponseException
value - new typejava.io.IOException - io error occurredServerResponseException - server replied with error codepublic char getType()
public void mode(char value)
throws java.io.IOException,
ServerResponseException
value - new data transfer modejava.io.IOException - io error occurredServerResponseException - server replied with an error code
public void abor()
throws java.io.IOException,
ServerResponseException
java.io.IOException - a socket IO error occurredServerResponseException - the server responded with an error code
public void abor(java.lang.String modem)
throws java.io.IOException,
ServerResponseException
modem - the modem to abort the command onjava.io.IOException - a socket IO error occurredServerResponseException - the server responded with an error
public void port(java.net.InetAddress address,
int port)
throws java.io.IOException,
ServerResponseException
address - address that we'll be listening onport - port on given address we'll be listening onjava.io.IOException - io error occurredServerResponseException - server replied with an error code
public java.lang.String stot(java.io.InputStream data)
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurred talking to the serverServerResponseException - server replied with error code
public java.lang.String stou(java.io.InputStream in)
throws java.io.IOException,
ServerResponseException
java.io.IOException - a socket IO error occurredServerResponseException - the server responded with an error code
public void stor(java.io.InputStream in,
java.lang.String pathname)
throws java.io.IOException,
ServerResponseException
pathname - name of file to store on server (where to put the file on the server)java.io.IOException - a socket IO error occurredServerResponseException - the server responded with an error
public java.lang.String syst()
throws java.io.IOException,
ServerResponseException
java.io.IOException - a socket IO error occurredServerResponseException - the server replied with an error code
public void stru(char value)
throws java.io.IOException,
ServerResponseException
value - file structure settingjava.io.IOException - io error occurredServerResponseException - server replied with an error code
public void list(java.lang.String path)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
This method relies on a data port (passive or active) to receive the list data. it is recommended that you use the getList() wrapper method rather than this method directly.
path - path of file or directory to get listing. A null path will get the listing of the current directory.java.io.IOException - io error occurredServerResponseException - server replied with an error codejava.io.FileNotFoundException - the given path does not exist
public void list()
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
NOTE: uses list() with the null path.
This method relies on a data socket of some sort to receive the list data. It is recommended that you use the getList() convenience method rather than this one directly.
java.io.IOException - io error occurredServerResponseException - server replied with an error codejava.io.FileNotFoundException - server could not find the specified file
public void nlst(java.lang.String path)
throws java.io.IOException,
ServerResponseException,
java.io.FileNotFoundException
This method requires a data socket to receive the name list data. It is recommended that you use the getNameList() method instead of this method directly.
path - path of the file or directory to list, passing in null will result in listing the current directoryjava.io.IOException - io error occurredServerResponseException - server replied with an error codejava.io.FileNotFoundException - server could not find the specified file
public void nlst()
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error codejava.io.FileNotFoundException - server could not find the specified file
public void retr(java.lang.String path)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
path - the relative or absolute path to the file to retrievejava.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating an errorjava.io.FileNotFoundException - the given path does not exist
public long size(java.lang.String pathname)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
pathname - the name of the file to get the size forjava.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating an errorjava.io.FileNotFoundException - the given path does not exist
public java.util.Date mdtm(java.lang.String pathname)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException,
java.text.ParseException
http://www.ietf.org/internet-drafts/draft-ietf-ftpext-mlst-15.txt.
The date is returned in GMT in a string of the following format:
YYYYMMDDhhmmss.ddd where .ddd is an optional
suffix reporting milliseconds. This method attempts to parse the
string returned by the server and present the caller with a
java.util.Date instance.
pathname - the name of the file to get the last-modified time forjava.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating
an errorjava.io.FileNotFoundException - the given path does not existjava.text.ParseException - the server returned an unrecognized date format
public void rnfr(java.lang.String pathname)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
pathname - the name of the file to be renamedjava.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating
an errorjava.io.FileNotFoundException - the given path does not exist
public void rnto(java.lang.String pathname)
throws java.io.IOException,
ServerResponseException
pathname - the name of the file to be renamedjava.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating
an error
public java.util.Vector stat(java.lang.String path)
throws java.io.IOException,
java.io.FileNotFoundException,
ServerResponseException
path - the directory or file to get the status of, using a null path will cause this method to return the server status informationjava.io.IOException - caused by a socket IO errorjava.io.FileNotFoundException - the given path or file does not existServerResponseException - caused by a server response indicating an error
public java.util.Vector stat()
throws java.io.IOException,
ServerResponseException
java.io.IOException - caused by a socket IO errorServerResponseException - caused by a server response indicating an error
public PassiveParameters pasv()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error code
public void quit()
throws java.io.IOException,
ServerResponseException
java.io.IOException - io error occurredServerResponseException - server replied with an error codepublic java.lang.String getGreeting()
public void setDebug(boolean value)
value - new debug flag valuepublic boolean getDebug()
protected java.lang.String readResponse(java.io.BufferedReader input)
throws java.io.IOException
input - the BufferedReader to read data fromjava.io.IOException - an IO error occurred
protected void connect(java.lang.String host,
int portnumber)
throws java.net.UnknownHostException,
java.io.IOException,
ServerResponseException
host - the hostname of the server to connect toportnumber - the port that the server is listening onjava.net.UnknownHostException - the given host name cannot be resolvedjava.io.IOException - an IO error occurredServerResponseException - the server responded with an error
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||