|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.lamatek.protobeans.FTPBean
public class FTPBean
FTPBean provides a consistent interface to an FTP Server. It provides all command submission, reponse handling and file transfer functions for the user, removing the tiresome task of error checking.
The FTPBean connects to the FTP server when instantiated, and is instantly ready for command submission or file transfer.
File transfers are handled through a different dataport than the communications port, and is determined using the PASV command.
Typical use of the FTPBean to transfer a file would be programmed as such:
try {As you can see, the entire process can be handled using only one try/catch loop. With all possible errors being extended by FTPException.
FTPBean remote = new FTPBean(getCodeBase().getHost(), 21, "myName", "myPassword");
remote.setDirectory("my/directory");
remote.storeFile("remotefilename.ext", "localfile.ext", FTPBean.ASCII);
remote.logout();
}
catch(FTPException ftp) {
System.out.println("Error occured during file transmission:\r\n" + ftp.getMessage());
}
| Field Summary | |
|---|---|
static int |
ASCII
Static variable used to define ASCII content. |
static int |
BINARY
Static variable used to define BINARY content. |
| Constructor Summary | |
|---|---|
FTPBean(boolean verbose)
This no argument constructor creates an initially unlogged FTPBean. |
|
FTPBean(java.lang.String server,
int port,
boolean verbose)
This constructor creates an FTPBean with the initial socket connection already established. |
|
FTPBean(java.lang.String server,
int port,
java.lang.String username,
java.lang.String password,
boolean verbose)
This constructor for the FTPBean provides all login and dataSocket functions during initialization. |
|
| Method Summary | |
|---|---|
boolean |
appendFile(java.lang.String filename,
java.lang.String file,
int type)
This method is similar to the storeFile method,
only it appends the data to an already existing file, or if a file with the give name cannot
be found, then it creates a new one. |
boolean |
appendText(java.lang.String filename,
java.lang.String data)
This method is similar to the storeText method,
only it appends the data to an already existing file, or if a file with the give name cannot
be found, then it creates a new one. |
java.lang.String |
completeDownload()
This method is an accessory method that reads any leftover text in the control port's input stream. |
boolean |
deleteFile(java.lang.String filename)
This method removes the specified file from the FTP Server. |
java.lang.String |
getDirectoryTree()
This method requests the directory structure from the FTP server using the current directory as the top. |
java.lang.String |
getLastResponse()
This method returns the last reponse received from the FTP Server. |
java.lang.String |
getRemoteDirectory()
Reads the current directory on the remote FTP server. |
boolean |
login(java.lang.String username,
java.lang.String password)
This method attempts to login in to the remote FTP server using the supplied username and password arguments. |
void |
logout()
This method performs the required logging out functions. |
boolean |
makeDirectory(java.lang.String directory)
This method creates a new directory on the FTP Server. |
boolean |
removeDirectory(java.lang.String directory)
This method removes a directory from the remote FTP server. |
boolean |
renameFile(java.lang.String oldname,
java.lang.String newname)
This method renames a file on the FTP Server. |
boolean |
retrieveFile(java.lang.String filename,
int type)
This method retrieves a file from the remote server and saves it to the current directory with the same filename. |
java.lang.Object |
retrieveObject(java.lang.String filename,
boolean save)
This method retrieves a remote Java object and either returns it as an instance of Object (if save = false) or stores it locally in a file in the current directory with the same name (if save = true). |
java.lang.String |
retrieveText(java.lang.String filename,
boolean save)
This method reads a text file and either returns it as a String (if save = false) or saves it to a file in the current directory with the same name (if save = true); |
boolean |
setRemote(java.lang.String server,
int port)
This method sets the remote server and port number, creating the required input and output streams for command submission and reads connection reponse from server and puts the reponse in the lastreply String variable. |
boolean |
setRemoteDirectory(java.lang.String directory)
Sets the remote directory on the FTP server. |
boolean |
storeFile(java.lang.String remote,
java.lang.String local,
int type)
This command reads data from the supplied file and saves it to the server with the filename supplied. |
boolean |
storeObject(java.lang.String filename,
java.lang.Object object)
This method is used to persistently store a Java object to a remote server. |
boolean |
storeText(java.lang.String filename,
java.lang.String data)
This command the supplied text to the server with the given filename. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ASCII
public static final int BINARY
| Constructor Detail |
|---|
public FTPBean(boolean verbose)
setRemote
and login methods must be called.
public FTPBean(java.lang.String server,
int port,
boolean verbose)
throws FTPException
login method must be called.
FTPException - If an error code is received from the FTP Server during processing.
public FTPBean(java.lang.String server,
int port,
java.lang.String username,
java.lang.String password,
boolean verbose)
throws FTPException
server - The string representation of the FTP host. (From an applet this will almost
always be obtained using the Applet.getCodeBase().getHost() method.)port - The FTP port of the Host server. (Usually 21).username - The FTP login name to be used.password - The FTP password that correlates to the FTP login name.
FTPException - If an error code is received from the FTP Server during processing.| Method Detail |
|---|
public boolean setRemote(java.lang.String server,
int port)
throws FTPException
server - The String representation of the FTP Server Host (in an Applet
this value will almost always be obtained through Applet.getCodeBae().getHost()).port - The FTP port of the remote server (usually 21).
FTPException - If an error code is received from the FTP Server during processing.
public boolean login(java.lang.String username,
java.lang.String password)
throws FTPException
NOTE: This method must be preceeded with a successful call to
setRemote
username - FTP login namepassword - FTP password
FTPException - If an error code is received from the FTP Server during processing.
public void logout()
throws FTPException
FTPException - If an error code is received during logout.public java.lang.String getLastResponse()
public boolean setRemoteDirectory(java.lang.String directory)
throws FTPException
directory - The desired remote directory.
FTPException - If an error code is received from the FTP Server during processing.
public java.lang.String getRemoteDirectory()
throws FTPException
FTPException - If an error code is received from the FTP Server during processing.
public boolean storeFile(java.lang.String remote,
java.lang.String local,
int type)
throws FTPException
remote - the remote filename to be used to store the file.local - The local filename to read data from.type - Data type. Either FTPBean.ASCII or FTPBean.BINARY.
FTPException - If an error code is received from the FTP Server during processing.
public boolean storeText(java.lang.String filename,
java.lang.String data)
throws FTPException
filename - the filename to be used to store the filedata - the java.lang.String to store in the remote file.
FTPException - If an error code is received from the FTP Server during processing.
public boolean storeObject(java.lang.String filename,
java.lang.Object object)
throws FTPException
FTPException - If an error code is received during Object transfer.
public boolean appendFile(java.lang.String filename,
java.lang.String file,
int type)
throws FTPException
storeFile method,
only it appends the data to an already existing file, or if a file with the give name cannot
be found, then it creates a new one.
filename - The name of the existing remote file to append to.file - An instance of java.io.File that points to a local file that is to be read from.type - The file type. Either FTPBean.ASCII or FTPBean.BINARY.
FTPException - If an error code was received from the Server during transport.
public boolean appendText(java.lang.String filename,
java.lang.String data)
throws FTPException
storeText method,
only it appends the data to an already existing file, or if a file with the give name cannot
be found, then it creates a new one.
FTPException - If an error code was received from the Server during transport.
public java.lang.String getDirectoryTree()
throws FTPException
FTPException - If an error code is received from the FTP Server during processing.
public boolean removeDirectory(java.lang.String directory)
throws FTPException
directory - The directory to remote (can be either absolute or relative)
FTPException - If an error code is received from the FTP Server during processing.
public boolean makeDirectory(java.lang.String directory)
throws FTPException
directory - The name of the new directory. (can be relative or absolute)
FTPException - If an error code is received from the FTP Server during processing.
public boolean deleteFile(java.lang.String filename)
throws FTPException
NOTE: it is assumed that the class implementing FTPBean provides all necessary assurances that the file should be deleted.
filename - The file to remove (can be absolute or relative)
FTPException - If an error code is received from the FTP Server during processing.
public boolean renameFile(java.lang.String oldname,
java.lang.String newname)
throws FTPException
NOTE: It is assumed that the class file implementing this FTPBean has performed all necessary checks before this method is called.
oldname - The current name of the remote file.newname - The new name for the remote file.
FTPException - If an error code is received from the FTP Server during processing.
public boolean retrieveFile(java.lang.String filename,
int type)
throws FTPException
filename - The file to retrievetype - The file type to read. Either FTPBean.ASCII or FTPBean.BINARY
FTPException - If an error code is received from the FTP Server during processing.
public java.lang.Object retrieveObject(java.lang.String filename,
boolean save)
throws FTPException
filename - The remote and local filename (if applicable)save - True if you wish to save in a file, or false if you want
the object returned for future use.
FTPException - If an error occurs during object loading.
public java.lang.String retrieveText(java.lang.String filename,
boolean save)
throws FTPException
filename - The remote file to read fromsave - True to save to file or False to return as a String
FTPException - If an error occurs during file download.
public java.lang.String completeDownload()
throws FTPException
retrieveFile.
FTPException - If the control port's input stream is null.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||