Class Ftp

Class Ftp

java.lang.Object
   |
   +----Ftp

class Ftp
extends Object
Ftp class Capabilities :
- Open a Ftp session (with USER, and PASSWORD)
- Get a file
- See a directory
- Send a command
- See the Ftp's result
TO DO:
- Add all the commands to put files on the server
- etc.
author Ebele Nicolas (ebele@essi.fr) Note: this is my real first class in java ....
PLEASE FEEL FREE TO SEND ANY COMMENTS (thanks ...)
How to use Example:
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class testFtp {
  public static void main(String[] args) {
    Ftp tFtp = new Ftp("anonymous:toto@nothing.com@ftp.inria.fr"); 
    if (tFtp.Open())
      {
	String list = tFtp.GetList();
	if (list == null)
	  System.err.println("unable to get the fic list");
	else
	  {
	    System.out.println("FicList=" + list);
	    if (!tFtp.GetFile("README"))
	      System.err.println("Get readme failed ....");
	    else
	      {
		if (!tFtp.GetFile("wrong file"))
		  System.err.println("Get wrongfile failed ....");
		else
		  {
		    System.out.println(tFtp.GetResult());
		    tFtp.ClearResult();
		    tFtp.Close();
		  }
	      }
	  }
      }
    else
      System.err.println("unable to open the connection");
  }
}

Variable Index

 o ClassName
 o Connection
the control Socket
 o ErrorFtp
 o IpAddress
the local IP address
 o is
the input stream from the ftp server
 o NbTriesDataPort
Number of tries to open a the dataport
 o NbTriesLogOn
Number of tries to log on the remote server
 o NbTriesOpenConnection
Number of tries to open the connection
 o Open
connection opened ??
 o os
the output stream towards the ftp server
 o Pass
the USER password
 o PassDefault
The default PASSWORD = "toto
 o Port
the control port
 o PortDefault
The Control port (value 21)
 o serverSocket
The socket for data transfert
 o TextRes
The result'text from the server
 o Url
the FTP address
 o User
the USER name
 o UserDefault
The default USER name = "anonymous"

Method Index

 o Ascii()
Change the connection to ascii
 o Bin()
Change the connection to bin
 o CD()
Change dir to root
 o CD(String)
Change the remote dir
 o ClearResult()
Clear the result sent by the Ftp server
 o Close()
Close the remote connection
 o Command(String)
Send a command to the ftp server
 o Command(String, boolean)
Send a command to the ftp server
 o erreurText()
erreurText
 o GetFile(String)
Get a file from the ftp server
 o GetFile(String, String)
Get a file from the ftp server
 o GetFullList()
Get the file'list of the curent directory (ls -la)
 o GetFullList(String)
Get the file'list of the curent directory (ls -la)
 o GetList()
Get the file'list of the curent directory (ls)
 o GetList(String)
Get the file'list of the curent directory (ls)
 o GetResult()
Get the result sent by the Ftp server
 o getUrl()
 o Log_On()
Log on the ftp server with the curent username, and the curent password
 o Log_On(String, String)
Log on the ftp server with a new username, and a new password set the connection to bin
 o Open()
know if there is an opened connection
 o PutFile(String)
Store a file from the ftp server
 o PutFile(String, String)
Store a file from the ftp server

Variables

 o ClassName
  public final static String ClassName
 o ErrorFtp
  protected final int ErrorFtp
 o PortDefault
  protected final int PortDefault
The Control port (value 21)
 o UserDefault
  protected final String UserDefault
The default USER name = "anonymous"
 o PassDefault
  protected final String PassDefault
The default PASSWORD = "toto@nothing.com"
 o Connection
  protected Socket Connection
the control Socket
 o Url
  protected String Url
the FTP address
 o User
  protected String User
the USER name
 o Pass
  protected String Pass
the USER password
 o Port
  protected int Port
the control port
 o IpAddress
  protected String IpAddress
the local IP address
 o os
  protected DataOutputStream os
the output stream towards the ftp server
 o is
  protected DataInputStream is
the input stream from the ftp server
 o Open
  protected boolean Open
connection opened ??
 o TextRes
  protected StringBuffer TextRes
The result'text from the server
 o serverSocket
  protected ServerSocket serverSocket
The socket for data transfert
 o NbTriesDataPort
  public int NbTriesDataPort
Number of tries to open a the dataport
 o NbTriesOpenConnection
  public int NbTriesOpenConnection
Number of tries to open the connection
 o NbTriesLogOn
  public int NbTriesLogOn
Number of tries to log on the remote server

Methods

 o Command
  public boolean Command(String Command)
Send a command to the ftp server
Parameters:
Command - the command sent to the server
Returns:
true if the command have be sent, false if not
 o Command
  public boolean Command(String Command,
                         boolean wait)
Send a command to the ftp server
Parameters:
Command - the command sent to the server
wait, - wait for the server answer
Returns:
true if the command have be sent, false if not
 o GetFile
  public boolean GetFile(String file)
Get a file from the ftp server
Parameters:
file - the file to get, it is saved on the local machine with the same name
Returns:
true if the file have been get, false if not
 o GetFile
  public boolean GetFile(String file,
                         String dest)
Get a file from the ftp server
Parameters:
file - the file to get
dest - the file saved on the local machine
Returns:
true if the file have been get, false if not
 o PutFile
  public boolean PutFile(String file)
Store a file from the ftp server
Parameters:
file - the file to store, it is saved on the remote machine with the same name
Returns:
true if the file have been stored, false if not
 o PutFile
  public boolean PutFile(String file,
                         String dest)
Store a file from the ftp server
Parameters:
file - the file to store
dest - the file saved on the remote machine
Returns:
true if the file have been stored, false if not
 o GetFullList
  public String GetFullList()
Get the file'list of the curent directory (ls -la)
Parameters:
no - param
Returns:
the string contening the file'list
 o GetFullList
  public String GetFullList(String dir)
Get the file'list of the curent directory (ls -la)
Parameters:
dir - : the path
Returns:
the string contening the file'list
 o GetList
  public String GetList()
Get the file'list of the curent directory (ls)
Parameters:
no - param
Returns:
the string contening the file'list
 o GetList
  public String GetList(String dir)
Get the file'list of the curent directory (ls)
Parameters:
dir - the path
Returns:
the string contening the file'list
 o CD
  public boolean CD()
Change dir to root
Parameters:
no - param
Returns:
true if the command have been sent, false if not
 o CD
  public boolean CD(String newdir)
Change the remote dir
Parameters:
newdir - the new remote directory
Returns:
true if the command have been sent, false if not
 o GetResult
  public String GetResult()
Get the result sent by the Ftp server
Parameters:
no - param
 o ClearResult
  public void ClearResult()
Clear the result sent by the Ftp server
Parameters:
no - param
 o Bin
  public boolean Bin()
Change the connection to bin
Parameters:
no - param
Returns:
true if the command have been sent, false if not
 o Ascii
  public boolean Ascii()
Change the connection to ascii
Returns:
true if the command have been sent, false if not
 o Close
  public boolean Close()
Close the remote connection
Parameters:
no - param
Returns:
true if the command have been sent, false if not
 o Log_On
  public boolean Log_On()
Log on the ftp server with the curent username, and the curent password
Parameters:
no - param
 o Log_On
  public boolean Log_On(String user,
                        String pass)
Log on the ftp server with a new username, and a new password set the connection to bin
Parameters:
user - the new user name
pass - the new password
 o Open
  public boolean Open()
know if there is an opened connection
Parameters:
no - param
Returns:
true if a connection is opened, false if not
 o getUrl
  public String getUrl()
 o erreurText
  public String erreurText()
erreurText
Parameters:
no - param
Returns:
a string with the last error