|
FTP Client | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.amoebacode.ftp.FTPSocket
FTPSocket encapsulates all communication between the FTP client and the FTP server.
This class incorporates elements from Bret Taylor's FTPConection.
| Field Summary | |
private java.net.Socket |
connectionSocket
The communication socket connecting the FTP client and server |
private boolean |
debugMode
Indicates whether server responses should be logged |
private java.io.BufferedReader |
inputStream
The input stream for the primary communication socket |
private java.lang.String |
lineSeparator
The line separator used for sending commands (default value is the "line.seperator" System property) |
private java.io.PrintStream |
outputStream
The output stream for the primary communication socket |
private int |
socketTimeout
The socket timeout delay |
| Constructor Summary | |
protected |
FTPSocket(int socketTimeout,
boolean debugMode)
Default protected constructor. |
| Method Summary | |
protected void |
closeConnection()
Closes this connection from the FTP server. |
private void |
debugPrint(java.lang.String message)
When debug mode is on, prints the specified message to the System output stream. |
private FTPServerResponse |
executeCommand(java.lang.String command)
Sends the specified command to the FTP server. |
protected FTPServerResponse |
executeCompleteCommand(java.lang.String command)
Sends the specified command to the FTP server (expecting a positive complete response). |
protected void |
executeDataCommand(java.lang.String command,
java.io.InputStream in)
Sends the specified data command to the FTP server, then transfers the contents of the specified input stream. |
protected void |
executeDataCommand(java.lang.String command,
java.io.OutputStream out)
Sends the specified data command to the FTP server, transferring the results to the specified output stream. |
protected FTPServerResponse |
executeIntermediateCommand(java.lang.String command)
Sends the specified command to the FTP server (expecting a positive intermediate response). |
protected FTPServerResponse |
executePreliminaryCommand(java.lang.String command)
Sends the specified command to the FTP server (expecting a positive preliminary response). |
private java.net.Socket |
getDataSocket()
Creates and returns a data socket between the client and the FTP server. |
private FTPServerResponse |
getServerResponse()
Returns the FTP server response to the last client command. |
protected void |
openConnection(java.lang.String host,
int port)
Opens a connection to the specified host through the specified port. |
protected void |
readDataToFile(java.lang.String command,
java.lang.String fileName)
Sends the specified data command to the FTP server, transferring the results to the file at the specified path. |
protected java.lang.String[] |
readDataToString(java.lang.String command)
Sends the specified data command to the FTP server, returning the results as a String array. |
void |
setLineSeparator(java.lang.String lineSeparator)
Sets the line separator used for sending commands. |
protected void |
setTransferType(boolean ascii)
Sets the transfer type (ASCII or binary) for this connection. |
private void |
transferData(java.io.InputStream in,
java.io.OutputStream out)
Transfers data in one kilobyte blocks from the specified input stream to the specified output stream. |
protected void |
writeDataFromFile(java.lang.String command,
java.lang.String fileName)
Sends the specified data command to the FTP server, then transfers the contents of the file at the specified path. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private boolean debugMode
private java.net.Socket connectionSocket
private java.io.PrintStream outputStream
private java.io.BufferedReader inputStream
private int socketTimeout
private java.lang.String lineSeparator
| Constructor Detail |
protected FTPSocket(int socketTimeout,
boolean debugMode)
socketTimeout - specifies the socket timeout delaydebugMode - indicates whether server responses should be logged| Method Detail |
protected void openConnection(java.lang.String host,
int port)
throws java.net.UnknownHostException,
java.io.IOException,
IllegalFTPResponseException
host - the host address of the FTP serverport - the FTP server connection port
IllegalFTPResponseException - if a positive complete response
is not received
java.net.UnknownHostException
java.io.IOException
protected void closeConnection()
throws java.io.IOException
java.io.IOException
protected void setTransferType(boolean ascii)
throws java.io.IOException,
IllegalFTPResponseException
ascii - the new transfer type
java.io.IOException
IllegalFTPResponseException
private FTPServerResponse getServerResponse()
throws java.io.IOException
java.io.IOException
private FTPServerResponse executeCommand(java.lang.String command)
throws java.io.IOException
command - the command to send to the FTP server
java.io.IOException
protected FTPServerResponse executeCompleteCommand(java.lang.String command)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP server
IllegalFTPResponseException - if a positive complete response
is not received
java.io.IOException
protected FTPServerResponse executeIntermediateCommand(java.lang.String command)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP server
IllegalFTPResponseException - if a positive intermediate
response is not received
java.io.IOException
protected FTPServerResponse executePreliminaryCommand(java.lang.String command)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP server
IllegalFTPResponseException - if a positive preliminary
response is not received
java.io.IOException
protected void readDataToFile(java.lang.String command,
java.lang.String fileName)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP serverfileName - the path to the destination file
java.io.IOException
IllegalFTPResponseException
protected java.lang.String[] readDataToString(java.lang.String command)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP server
java.io.IOException
IllegalFTPResponseException
protected void writeDataFromFile(java.lang.String command,
java.lang.String fileName)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP serverfileName - the path to the source file
java.io.IOException
IllegalFTPResponseException
protected void executeDataCommand(java.lang.String command,
java.io.OutputStream out)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP serverout - the destination output stream
java.io.IOException
IllegalFTPResponseException
protected void executeDataCommand(java.lang.String command,
java.io.InputStream in)
throws java.io.IOException,
IllegalFTPResponseException
command - the command to send to the FTP serverin - the source input stream
java.io.IOException
IllegalFTPResponseExceptionpublic void setLineSeparator(java.lang.String lineSeparator)
lineSeparator - the new line separator String
private java.net.Socket getDataSocket()
throws java.io.IOException
java.io.IOException
private void transferData(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the source streamout - the destination stream
java.io.IOExceptionprivate void debugPrint(java.lang.String message)
message - the String to print
|
FTP Client | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||