com.dalsemi.protocol.ftp
Class FTPClient

java.lang.Object
  |
  +--com.dalsemi.protocol.BasicClient
        |
        +--com.dalsemi.protocol.ftp.FTPClient

public class FTPClient
extends com.dalsemi.protocol.BasicClient


Field Summary
 boolean binary
          Binary/ASCII mode flag.
static java.lang.String TIMEOUT_PROPERTY_STRING
          System property String used to find a default socket timeout.
 
Fields inherited from class com.dalsemi.protocol.BasicClient
cin, control, controlPort, controlServer, cout, data, dataPort, dataServer, din, dout
 
Constructor Summary
FTPClient(java.lang.String SERVER)
          Create a connection to an FTP server running at the specified server on the default FTP port (21).
FTPClient(java.lang.String SERVER, int PORT)
          Create a connection to an FTP server running at the specified server on the specified port.
 
Method Summary
 void analyze(int code)
          Outputs an IOException with meaningful messages in the event of bad FTP return codes.
 int ascii()
          Changes to ASCII transfer mode.
 int binary()
          Changes to binary transfer mode.
 void close()
          Attempts to close all socket socket resources that may have been left open by any operation.
 int dataConnection()
          Sets up a connection to transfer a file either by entering passive mode or by making a connection using the PORT command.
 int ePassiveConnection()
          Sets up an enhanced passive connection to the FTP server.
 java.io.InputStream getDataStream()
          Gets the stream to read the file or directory listing information we had earlier requested using retr.
 int getFileSize()
          Get the size of a file we are downloading.
 java.lang.String getLastCommand()
          Gets the last command string that we sent to the FTP server.
 java.io.OutputStream getOutputStream()
          Gets the stream to write file information.
 java.lang.String getResponseString()
          Gets the last response string that we recieved from the FTP server.
 int issueCommand(java.lang.String command)
          Sends a command to the FTP server and returns the success code reported by the FTP server.
 int list(java.lang.String path)
          List the files in a directory pointed to by the path.
 int passiveConnection()
          Sets up a passive connection to the FTP server.
 int password(java.lang.String password)
          Sends a password to the FTP server.
 int port()
          Sets up a connection to transfer a file by using the PORT command.
 int quit()
          Logs out of the FTP server, and closes the FTP session.
 int retr(java.lang.String path)
          Issues a command to get a file from an FTP server.
 int userName(java.lang.String user)
          Sends a user name to login to an FTP server.
 
Methods inherited from class com.dalsemi.protocol.BasicClient
command, command, getTimeout, readDataStream, setTimeout, setupDataSocket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT_PROPERTY_STRING

public static final java.lang.String TIMEOUT_PROPERTY_STRING
System property String used to find a default socket timeout.

binary

public boolean binary
Binary/ASCII mode flag. Applications should not alter this variable. They should use the binary and ascii methods instead.
See Also:
binary(), ascii()
Constructor Detail

FTPClient

public FTPClient(java.lang.String SERVER)
          throws java.io.IOException
Create a connection to an FTP server running at the specified server on the default FTP port (21).
Parameters:
SERVER - address of the FTP server to connect to
Throws:
java.io.IOException - if socket/connection errors occur

FTPClient

public FTPClient(java.lang.String SERVER,
                 int PORT)
          throws java.io.IOException
Create a connection to an FTP server running at the specified server on the specified port. The default FTP server's port number is 21. If the system property FTP_PROTOCOL_HANDLER_SOTIMEOUT is defined, this method sets the control socket's timeout to the timeout specified by this property.
Parameters:
SERVER - address of the FTP server to connect to
PORT - port number the FTP server is listening on
Throws:
java.io.IOException - if socket/connection errors occur
Method Detail

userName

public int userName(java.lang.String user)
             throws java.io.IOException
Sends a user name to login to an FTP server. Sends anonymous if no user is specified.
Parameters:
user - User name for FTP login, or null to use anonymous.
Returns:
FTP response code to the USER command
Throws:
java.io.IOException - if socket errors occur

password

public int password(java.lang.String password)
             throws java.io.IOException
Sends a password to the FTP server. This method should be called immediately after the userName method. If we are doing anonymous login, send something that looks like an email address.
Parameters:
password - The password to login to an FTP server. If null, the string user@ will be sent.
Returns:
FTP response code to the PASS command
Throws:
java.io.IOException - if socket errors occur
See Also:
userName(java.lang.String)

binary

public int binary()
           throws java.io.IOException
Changes to binary transfer mode. This mode can be used for any kind of file transmission, and should always be used if the file is not text.
Returns:
FTP response code to the TYPE command
Throws:
java.io.IOException - if socket errors occur

ascii

public int ascii()
          throws java.io.IOException
Changes to ASCII transfer mode. This mode should only be used to transfer text files.
Returns:
FTP response code to the TYPE command
Throws:
java.io.IOException - if socket errors occur

passiveConnection

public int passiveConnection()
                      throws java.io.IOException
Sets up a passive connection to the FTP server. This mode forces the FTP server to open a server socket in order to transfer a file.
Returns:
FTP response code to the PASV command
Throws:
java.io.IOException - if socket errors occur

ePassiveConnection

public int ePassiveConnection()
                       throws java.io.IOException
Sets up an enhanced passive connection to the FTP server. This mode forces the FTP server to open a server socket in order to transfer a file. This method allows for IPv6 addresses as well.
Returns:
FTP response code to the EPSV command
Throws:
java.io.IOException - if socket errors occur

dataConnection

public int dataConnection()
                   throws java.io.IOException
Sets up a connection to transfer a file either by entering passive mode or by making a connection using the PORT command.
Returns:
FTP response code to the connection command
Throws:
java.io.IOException - if socket errors occur

port

public int port()
         throws java.io.IOException
Sets up a connection to transfer a file by using the PORT command. This mode sets up a server socket on the local machine and tells the FTP server how to contact that socket.
Returns:
FTP response code to the PORT command
Throws:
java.io.IOException - if socket errors occur

retr

public int retr(java.lang.String path)
         throws java.io.IOException
Issues a command to get a file from an FTP server. Also parses the response string for the proper size of the file. Filesize is invalid for directories. After this method, the #getDataStream method should be called to read the file data.
Parameters:
path - path to the file on the FTP server to download
Returns:
FTP response code to the RETR command
Throws:
java.io.IOException - if socket errors occur

list

public int list(java.lang.String path)
         throws java.io.IOException
List the files in a directory pointed to by the path. Listing data returned appears as if ls -l had been called.
Parameters:
path - directory name to get the listing for. If path is null, the directory listing for the current directory is requested
Returns:
FTP response code to the RETR command
Throws:
java.io.IOException - if socket errors occur

getFileSize

public int getFileSize()
Get the size of a file we are downloading.
Returns:
size of the file we are downloading or have jsut requested

quit

public int quit()
         throws java.io.IOException
Logs out of the FTP server, and closes the FTP session.
Returns:
FTP response code to the QUIT command
Throws:
java.io.IOException - if socket errors occur

issueCommand

public int issueCommand(java.lang.String command)
                 throws java.io.IOException
Sends a command to the FTP server and returns the success code reported by the FTP server.
Parameters:
command - string command to be send to the FTP server. command must include the end-of-line sequence if it is required
Returns:
FTP response code to the given command
Throws:
java.io.IOException - if socket errors occur

getDataStream

public java.io.InputStream getDataStream()
                                  throws java.io.IOException
Gets the stream to read the file or directory listing information we had earlier requested using retr.
Returns:
Input stream to the resource to read
Throws:
java.io.IOException - if socket errors occur
See Also:
retr(java.lang.String)

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Gets the stream to write file information. Notice that this FTP Client implementation has no put method. Please see the Slush command source file com.dalsemi.slush.command.FTPCommand for a way to implement the common FTP put command.
Returns:
Output stream for the resource to write
Throws:
java.io.IOException - if socket errors occur

analyze

public void analyze(int code)
             throws java.io.IOException
Outputs an IOException with meaningful messages in the event of bad FTP return codes. This method should throw an IOException.
Parameters:
code - FTP response code to get a readable string for
Throws:
java.io.IOException - if the code matches a known error message

getResponseString

public java.lang.String getResponseString()
Gets the last response string that we recieved from the FTP server.
Returns:
Response string from FTP server for our last command

getLastCommand

public java.lang.String getLastCommand()
Gets the last command string that we sent to the FTP server.
Returns:
Last command we sent to the FTP server

close

public void close()
Attempts to close all socket socket resources that may have been left open by any operation. After this call, this FTPClient object will not be valid for further communication.


Also see:
o TINI 1.16 API
o TINI Home Page
o 1-Wire API

o JDK 1.1

Last update Wed Jun 8 17:19:36 CDT 2005