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");
}
}
-
ClassName
-
-
Connection
- the control Socket
-
ErrorFtp
-
-
IpAddress
- the local IP address
-
is
- the input stream from the ftp server
-
NbTriesDataPort
- Number of tries to open a the dataport
-
NbTriesLogOn
- Number of tries to log on the remote server
-
NbTriesOpenConnection
- Number of tries to open the connection
-
Open
- connection opened ??
-
os
- the output stream towards the ftp server
-
Pass
- the USER password
-
PassDefault
- The default PASSWORD = "toto
-
Port
- the control port
-
PortDefault
- The Control port (value 21)
-
serverSocket
- The socket for data transfert
-
TextRes
- The result'text from the server
-
Url
- the FTP address
-
User
- the USER name
-
UserDefault
- The default USER name = "anonymous"
-
Ascii()
- Change the connection to ascii
-
Bin()
- Change the connection to bin
-
CD()
- Change dir to root
-
CD(String)
- Change the remote dir
-
ClearResult()
- Clear the result sent by the Ftp server
-
Close()
- Close the remote connection
-
Command(String)
- Send a command to the ftp server
-
Command(String, boolean)
- Send a command to the ftp server
-
erreurText()
- erreurText
-
GetFile(String)
- Get a file from the ftp server
-
GetFile(String, String)
- Get a file from the ftp server
-
GetFullList()
- Get the file'list of the curent directory (ls -la)
-
GetFullList(String)
- Get the file'list of the curent directory (ls -la)
-
GetList()
- Get the file'list of the curent directory (ls)
-
GetList(String)
- Get the file'list of the curent directory (ls)
-
GetResult()
- Get the result sent by the Ftp server
-
getUrl()
-
-
Log_On()
- Log on the ftp server with the curent username, and the curent password
-
Log_On(String, String)
- Log on the ftp server with a new username, and a new password
set the connection to bin
-
Open()
- know if there is an opened connection
-
PutFile(String)
- Store a file from the ftp server
-
PutFile(String, String)
- Store a file from the ftp server
ClassName
public final static String ClassName
ErrorFtp
protected final int ErrorFtp
PortDefault
protected final int PortDefault
- The Control port (value 21)
UserDefault
protected final String UserDefault
- The default USER name = "anonymous"
PassDefault
protected final String PassDefault
- The default PASSWORD = "toto@nothing.com"
Connection
protected Socket Connection
- the control Socket
Url
protected String Url
- the FTP address
User
protected String User
- the USER name
Pass
protected String Pass
- the USER password
Port
protected int Port
- the control port
IpAddress
protected String IpAddress
- the local IP address
os
protected DataOutputStream os
- the output stream towards the ftp server
is
protected DataInputStream is
- the input stream from the ftp server
Open
protected boolean Open
- connection opened ??
TextRes
protected StringBuffer TextRes
- The result'text from the server
serverSocket
protected ServerSocket serverSocket
- The socket for data transfert
NbTriesDataPort
public int NbTriesDataPort
- Number of tries to open a the dataport
NbTriesOpenConnection
public int NbTriesOpenConnection
- Number of tries to open the connection
NbTriesLogOn
public int NbTriesLogOn
- Number of tries to log on the remote server
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
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
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
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
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
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
GetFullList
public String GetFullList()
- Get the file'list of the curent directory (ls -la)
- Parameters:
- no - param
- Returns:
- the string contening the file'list
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
GetList
public String GetList()
- Get the file'list of the curent directory (ls)
- Parameters:
- no - param
- Returns:
- the string contening the file'list
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
CD
public boolean CD()
- Change dir to root
- Parameters:
- no - param
- Returns:
- true if the command have been sent, false if not
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
GetResult
public String GetResult()
- Get the result sent by the Ftp server
- Parameters:
- no - param
ClearResult
public void ClearResult()
- Clear the result sent by the Ftp server
- Parameters:
- no - param
Bin
public boolean Bin()
- Change the connection to bin
- Parameters:
- no - param
- Returns:
- true if the command have been sent, false if not
Ascii
public boolean Ascii()
- Change the connection to ascii
- Returns:
- true if the command have been sent, false if not
Close
public boolean Close()
- Close the remote connection
- Parameters:
- no - param
- Returns:
- true if the command have been sent, false if not
Log_On
public boolean Log_On()
- Log on the ftp server with the curent username, and the curent password
- Parameters:
- no - param
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
Open
public boolean Open()
- know if there is an opened connection
- Parameters:
- no - param
- Returns:
- true if a connection is opened, false if not
getUrl
public String getUrl()
erreurText
public String erreurText()
- erreurText
- Parameters:
- no - param
- Returns:
- a string with the last error