Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.enterprisedt.net.ftp
Class FTPClient  view FTPClient download FTPClient.java

java.lang.Object
  extended bycom.enterprisedt.net.ftp.FTPClient

public class FTPClient
extends java.lang.Object

Supports client-side FTP. Most common FTP operations are present in this class.

Version:
$Revision: 1.3 $

Field Summary
private  FTPConnectMode connectMode
          Record of the connect mode - make the default PASV (as this was the original mode supported)
private  FTPControlSocket control
          Socket responsible for controlling the connection
private static java.lang.String cvsId
          Revision control id
private  FTPDataSocket data
          Socket responsible for transferring the data
private  int timeout
          Socket timeout for both data and control.
private  FTPTransferType transferType
          Record of the transfer type - make the default ASCII
 
Constructor Summary
FTPClient(java.net.InetAddress remoteAddr)
          Constructor.
FTPClient(java.net.InetAddress remoteAddr, int controlPort)
          Constructor.
FTPClient(java.lang.String remoteHost)
          Constructor.
FTPClient(java.lang.String remoteHost, int controlPort)
          Constructor.
 
Method Summary
 void chdir(java.lang.String dir)
          Change the remote working directory to that supplied
 void debugResponses(boolean on)
          Switch debug of responses on or off
 void delete(java.lang.String remoteFile)
          Delete the specified remote file
 java.lang.String[] dir(java.lang.String mask)
          List a directory's contents as an array of strings of filenames.
 java.lang.String[] dir(java.lang.String mask, boolean full)
          List a directory's contents as an array of strings.
 byte[] get(java.lang.String remoteFile)
          Get data from the FTP server.
 java.io.InputStream get(java.lang.String remoteFile, long byteSkip)
          Get data from the FTP server.
 void get(java.lang.String localPath, java.lang.String remoteFile)
          Get data from the FTP server.
private  void getASCII(java.lang.String localPath, java.lang.String remoteFile)
          Get as ASCII, i.e.
private  void getBinary(java.lang.String localPath, java.lang.String remoteFile)
          Get as binary file, i.e.
 int getFileSize(java.lang.String remoteFile)
           
(package private)  java.lang.String getRemoteHostName()
          Get the name of the remote host
 FTPTransferType getType()
          Get the current transfer type
private  void initGet(java.lang.String remoteFile)
          Request to the server that the get is set up
private  void initPut(java.lang.String remoteFile, boolean append)
          Request the server to set up the put
 void initSOCKS(java.lang.String port, java.lang.String host)
          Set up SOCKS v4 proxy settings.
 java.lang.String list(java.lang.String mask)
          Deprecated. As of FTP 1.1, replaced by dir(String) 55
 java.lang.String list(java.lang.String mask, boolean full)
          Deprecated. As of FTP 1.1, replaced by dir(String,boolean) 55
 void login(java.lang.String user, java.lang.String password)
          Login into an account on the FTP server.
 void mkdir(java.lang.String dir)
          Create the specified remote working directory
 void password(java.lang.String password)
          Supplies the password for a previously supplied username to log into the FTP server.
 void put(byte[] bytes, java.lang.String remoteFile)
          Put data onto the FTP server.
 void put(byte[] bytes, java.lang.String remoteFile, boolean append)
          Put data onto the FTP server.
 void put(java.lang.String localPath, java.lang.String remoteFile)
          Put a local file onto the FTP server.
 void put(java.lang.String localPath, java.lang.String remoteFile, boolean append)
          Put a local file onto the FTP server.
private  void putASCII(java.lang.String localPath, java.lang.String remoteFile, boolean append)
          Put as ASCII, i.e.
private  void putBinary(java.lang.String localPath, java.lang.String remoteFile, boolean append)
          Put as binary, i.e.
 java.lang.String pwd()
          Get the current remote working directory
 void quit()
          Quit the FTP session
 void quote(java.lang.String command, java.lang.String[] validCodes)
          Issue arbitrary ftp commands to the FTP server.
 void rename(java.lang.String from, java.lang.String to)
          Rename a file or directory
 void rmdir(java.lang.String dir)
          Delete the specified remote working directory
 void setConnectMode(FTPConnectMode mode)
          Set the connect mode
 void setTimeout(int millis)
          Set the TCP timeout on the underlying socket.
 void setType(FTPTransferType type)
          Set the transfer type
 boolean site(java.lang.String command)
          Run a site-specific command on the server.
 java.lang.String system()
          Get the type of the OS at the server
 void user(java.lang.String user)
          Supply the user name to log into an account on the FTP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsId

private static java.lang.String cvsId
Revision control id


control

private FTPControlSocket control
Socket responsible for controlling the connection


data

private FTPDataSocket data
Socket responsible for transferring the data


timeout

private int timeout
Socket timeout for both data and control. In milliseconds


transferType

private FTPTransferType transferType
Record of the transfer type - make the default ASCII


connectMode

private FTPConnectMode connectMode
Record of the connect mode - make the default PASV (as this was the original mode supported)

Constructor Detail

FTPClient

public FTPClient(java.lang.String remoteHost)
          throws java.io.IOException,
                 FTPException
Constructor. Creates the control socket


FTPClient

public FTPClient(java.lang.String remoteHost,
                 int controlPort)
          throws java.io.IOException,
                 FTPException
Constructor. Creates the control socket


FTPClient

public FTPClient(java.net.InetAddress remoteAddr)
          throws java.io.IOException,
                 FTPException
Constructor. Creates the control socket


FTPClient

public FTPClient(java.net.InetAddress remoteAddr,
                 int controlPort)
          throws java.io.IOException,
                 FTPException
Constructor. Creates the control socket. Allows setting of control port (normally set by default to 21).

Method Detail

setTimeout

public void setTimeout(int millis)
                throws java.io.IOException
Set the TCP timeout on the underlying socket. If a timeout is set, then any operation which takes longer than the timeout value will be killed with a java.io.InterruptedException. We set both the control and data connections


setConnectMode

public void setConnectMode(FTPConnectMode mode)
Set the connect mode


login

public void login(java.lang.String user,
                  java.lang.String password)
           throws java.io.IOException,
                  FTPException
Login into an account on the FTP server. This call completes the entire login process


user

public void user(java.lang.String user)
          throws java.io.IOException,
                 FTPException
Supply the user name to log into an account on the FTP server. Must be followed by the password() method - but we allow for


password

public void password(java.lang.String password)
              throws java.io.IOException,
                     FTPException
Supplies the password for a previously supplied username to log into the FTP server. Must be preceeded by the user() method


initSOCKS

public void initSOCKS(java.lang.String port,
                      java.lang.String host)
Set up SOCKS v4 proxy settings. This can be used if there is a SOCKS proxy server in place that must be connected thru.


getRemoteHostName

java.lang.String getRemoteHostName()
Get the name of the remote host


quote

public void quote(java.lang.String command,
                  java.lang.String[] validCodes)
           throws java.io.IOException,
                  FTPException
Issue arbitrary ftp commands to the FTP server.


put

public void put(java.lang.String localPath,
                java.lang.String remoteFile)
         throws java.io.IOException,
                FTPException
Put a local file onto the FTP server. It is placed in the current directory.


put

public void put(java.lang.String localPath,
                java.lang.String remoteFile,
                boolean append)
         throws java.io.IOException,
                FTPException
Put a local file onto the FTP server. It is placed in the current directory. Allows appending if current file exists


initPut

private void initPut(java.lang.String remoteFile,
                     boolean append)
              throws java.io.IOException,
                     FTPException
Request the server to set up the put


putASCII

private void putASCII(java.lang.String localPath,
                      java.lang.String remoteFile,
                      boolean append)
               throws java.io.IOException,
                      FTPException
Put as ASCII, i.e. read a line at a time and write inserting the correct FTP separator


putBinary

private void putBinary(java.lang.String localPath,
                       java.lang.String remoteFile,
                       boolean append)
                throws java.io.IOException,
                       FTPException
Put as binary, i.e. read and write raw bytes


put

public void put(byte[] bytes,
                java.lang.String remoteFile)
         throws java.io.IOException,
                FTPException
Put data onto the FTP server. It is placed in the current directory.


put

public void put(byte[] bytes,
                java.lang.String remoteFile,
                boolean append)
         throws java.io.IOException,
                FTPException
Put data onto the FTP server. It is placed in the current directory. Allows appending if current file exists


get

public void get(java.lang.String localPath,
                java.lang.String remoteFile)
         throws java.io.IOException,
                FTPException
Get data from the FTP server. Uses the currently set transfer mode.


initGet

private void initGet(java.lang.String remoteFile)
              throws java.io.IOException,
                     FTPException
Request to the server that the get is set up


getASCII

private void getASCII(java.lang.String localPath,
                      java.lang.String remoteFile)
               throws java.io.IOException,
                      FTPException
Get as ASCII, i.e. read a line at a time and write using the correct newline separator for the OS


getBinary

private void getBinary(java.lang.String localPath,
                       java.lang.String remoteFile)
                throws java.io.IOException,
                       FTPException
Get as binary file, i.e. straight transfer of data


get

public java.io.InputStream get(java.lang.String remoteFile,
                               long byteSkip)
                        throws java.io.IOException,
                               FTPException
Get data from the FTP server. Transfers in whatever mode we are in. Returns the InputStream for the FTP connection.


getFileSize

public int getFileSize(java.lang.String remoteFile)
                throws java.io.IOException,
                       FTPException

get

public byte[] get(java.lang.String remoteFile)
           throws java.io.IOException,
                  FTPException
Get data from the FTP server. Transfers in whatever mode we are in. Retrieve as a byte array. Note that we may experience memory limitations as the entire file must be held in memory at one time.


site

public boolean site(java.lang.String command)
             throws java.io.IOException,
                    FTPException
Run a site-specific command on the server. Support for commands is dependent on the server


list

public java.lang.String list(java.lang.String mask)
                      throws java.io.IOException,
                             FTPException
Deprecated. As of FTP 1.1, replaced by dir(String) 55

List a directory's contents


list

public java.lang.String list(java.lang.String mask,
                             boolean full)
                      throws java.io.IOException,
                             FTPException
Deprecated. As of FTP 1.1, replaced by dir(String,boolean) 55

List a directory's contents as one string. A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server.


dir

public java.lang.String[] dir(java.lang.String mask)
                       throws java.io.IOException,
                              FTPException
List a directory's contents as an array of strings of filenames.


dir

public java.lang.String[] dir(java.lang.String mask,
                              boolean full)
                       throws java.io.IOException,
                              FTPException
List a directory's contents as an array of strings. A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server.


debugResponses

public void debugResponses(boolean on)
Switch debug of responses on or off


getType

public FTPTransferType getType()
Get the current transfer type


setType

public void setType(FTPTransferType type)
             throws java.io.IOException,
                    FTPException
Set the transfer type


delete

public void delete(java.lang.String remoteFile)
            throws java.io.IOException,
                   FTPException
Delete the specified remote file


rename

public void rename(java.lang.String from,
                   java.lang.String to)
            throws java.io.IOException,
                   FTPException
Rename a file or directory


rmdir

public void rmdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Delete the specified remote working directory


mkdir

public void mkdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Create the specified remote working directory


chdir

public void chdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Change the remote working directory to that supplied


pwd

public java.lang.String pwd()
                     throws java.io.IOException,
                            FTPException
Get the current remote working directory


system

public java.lang.String system()
                        throws java.io.IOException,
                               FTPException
Get the type of the OS at the server


quit

public void quit()
          throws java.io.IOException,
                 FTPException
Quit the FTP session