com.bristle.javalib.net.ftp
Class Ftp

java.lang.Object
  extended by com.bristle.javalib.net.ftp.Ftp

public class Ftp
extends Object

This class supports the ability to transfer files via FTP.

Usage:
   - The typical scenario for using this class is:
       Ftp ftp = new Ftp();
       ftp.connect(strServer, strUsername, strPassword); 
       ftp.putAsciiFile(strFilename, strContent);
       ftp.disconnect(); 

   - See the source code of the inner Tester class for more examples.
  
Assumptions:
Effects:
       - Transfers files via FTP.
Anticipated Changes:
       - Add more FTP features.  Currently, it supports only FTP PUT of ASCII
         files.
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class Ftp.FtpException
          This exception is thrown when something goes wrong during the FTP transfer.
static class Ftp.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
private  BufferedReader m_inputFromServerCommand
           
private  PrintWriter m_outputToServerCommand
           
private  Socket m_socketCommand
           
 
Constructor Summary
Ftp()
           
 
Method Summary
private  void cleanup()
          Cleanup the FTP connection releasing all resources.
 void connect(String strServer, String strUsername, String strPassword)
          Connect to the FTP server and login.
 void disconnect()
          Disconnect from the FTP server.
private  void ftpCommand(String strCommand, String strExpectedResponse)
          Send an FTP command to the server, throwing an exception if the expected response doesn't occur.
private  void getResponse(String strExpectedResponse)
          Throw an exception if the expected response didn't occur.
 void putAsciiFile(String strFilename, Reader readerContent)
          PUT an ASCII file to the FTP server.
 void putAsciiFile(String strFilename, String strContent)
          PUT an ASCII file to the FTP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_socketCommand

private Socket m_socketCommand

m_inputFromServerCommand

private BufferedReader m_inputFromServerCommand

m_outputToServerCommand

private PrintWriter m_outputToServerCommand
Constructor Detail

Ftp

public Ftp()
Method Detail

connect

public void connect(String strServer,
                    String strUsername,
                    String strPassword)
             throws Ftp.FtpException,
                    IOException
Connect to the FTP server and login.

Parameters:
strServer - DNS name or IP address of FTP server.
strUsername - Username for logging in to server.
strPassword - Password for logging in to server.
Throws:
Ftp.FtpException - When an FTP error, like login failure, occurs.
IOException - When an I/O error occurs.

cleanup

private void cleanup()
Cleanup the FTP connection releasing all resources.


disconnect

public void disconnect()
                throws Ftp.FtpException,
                       IOException
Disconnect from the FTP server.

Throws:
Ftp.FtpException - When an FTP error occurs.
IOException - When an I/O error occurs.

getResponse

private void getResponse(String strExpectedResponse)
                  throws Ftp.FtpException,
                         IOException
Throw an exception if the expected response didn't occur.

Parameters:
strExpectedResponse - Response expected from input stream.
Throws:
Ftp.FtpException - When wrong response occurs.
IOException - When an I/O error occurs.

ftpCommand

private void ftpCommand(String strCommand,
                        String strExpectedResponse)
                 throws Ftp.FtpException,
                        IOException
Send an FTP command to the server, throwing an exception if the expected response doesn't occur.

Parameters:
strCommand - FTP command to send.
strExpectedResponse - Response expected from input stream.
Throws:
Ftp.FtpException - When wrong response occurs.
IOException - When an I/O error occurs.

putAsciiFile

public void putAsciiFile(String strFilename,
                         Reader readerContent)
                  throws Ftp.FtpException,
                         IOException
PUT an ASCII file to the FTP server.

Parameters:
strFilename - Name of file to create on server.
readerContent - Reader containing content to write to the file.
Throws:
Ftp.FtpException - When an FTP error, like permission denied, occurs.
IOException - When an I/O error occurs.

putAsciiFile

public void putAsciiFile(String strFilename,
                         String strContent)
                  throws Ftp.FtpException,
                         IOException
PUT an ASCII file to the FTP server.

Parameters:
strFilename - Name of file to create on server.
strContent - String to write to the file.
Throws:
Ftp.FtpException - When an FTP error, like permission denied, occurs.
IOException - When an I/O error occurs.