|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--ftp.FtpBean
This bean provide some basic FTP functions.
You can use this bean in some visual development tools (eg. IBM VA)
or just include its file and use its methods.
This class is thread safe, only one thread can acquire the object and do some ftp operation at a time.
How to use it?
To start a new instance of this FTP bean
FtpBean ftp = new FtpBean();
// To connect to a FTP server
ftp.ftpConnect("servername", "username", "password");
// Some methods return null if you call them without establish connection first.
//Then just call the functions provided by this bean.
//After you end the ftp section. Just close the connection.
ftp.close();
Remarks:
1) When ever a ftp command failed (eg. Permission denied), the methods throw an FtpException.
So you need to catch the FtpException wherever you invoke those methods of this class.
2) This bean use passive mode to establish data connection by default.
If this cause problem from firewall of the network, try using active mode:
ftp.setPassiveModeTransfer(false);
3) To turn on debug mode, you need to change the source of this class. Then re-compile it.
IMPORTANT:
1) If you use this bean in an applet and the applet is open to the public,
please don't include the user name and password in
the source code of your applet. As anyone who can get your class files can get your
user name and password. It is reasonable to ask the user for user name and password
if you are going to use FTP in the applet.
2) If you use it in an applet, please be aware of the security restriction from the browser.
As an applet can ONLY connect to the host which serves it. Also, some methods in this bean
will write/read to the local file system. These methods are also restricted by the browser.
If you find any bugs in this bean or any comment, please give me a notice at
Calvin(citidancer@hongkong.com)
| Constructor Summary | |
FtpBean()
Constructor |
|
| Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
|
void |
close()
Close FTP connection. |
void |
execute(java.lang.String exec)
Execute a command using ftp. |
void |
fileDelete(java.lang.String filename)
Delete a file at the FTP server. |
void |
fileRename(java.lang.String oldfilename,
java.lang.String newfilename)
Rename a file at the FTP server. |
void |
ftpConnect(java.lang.String server,
java.lang.String user,
java.lang.String password)
Connect to FTP server and login. |
java.lang.String |
getAsciiFile(java.lang.String filename,
java.lang.String separator)
Get an ASCII file from the server and return as String. |
java.lang.String |
getAsciiFile(java.lang.String filename,
java.lang.String separator,
FtpObserver observer)
Get an ASCII file from the server and return as String. |
byte[] |
getBinaryFile(java.lang.String filename)
Get a binary file and return a byte array. |
byte[] |
getBinaryFile(java.lang.String filename,
FtpObserver observer)
Get a binary file and return a byte array. |
byte[] |
getBinaryFile(java.lang.String filename,
long restart)
Get a binary file at a restarting point. |
byte[] |
getBinaryFile(java.lang.String filename,
long restart,
FtpObserver observer)
Get a binary file at a restarting point. |
void |
getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile)
Read file from ftp server and write to a file in local hard disk. |
void |
getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
FtpObserver observer)
Read file from ftp server and write to a file in local hard disk. |
void |
getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
long restart)
Read file from ftp server and write to a file in local hard disk. |
void |
getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
long restart,
FtpObserver observer)
Read from a ftp file and restart at a specific point. |
java.lang.String |
getDirectory()
Get current directory name. |
FtpListResult |
getDirectoryContent()
Get the content of current directory |
java.lang.String |
getDirectoryContentAsString()
Get the content of current directory. |
int |
getPort()
Return the port number |
java.lang.String |
getReply()
Get reply of the last command. |
java.lang.String |
getReplyMessage()
Get reply message of the last command. |
java.lang.String |
getServerName()
Return the server name. |
java.lang.String |
getSystemType()
Get the type of operating system of the server. |
java.lang.String |
getUserName()
Return the user name. |
boolean |
isPassiveModeTransfer()
Return true if it is using passive transfer mode. |
void |
makeDirectory(java.lang.String directory)
Make a directory in the server. |
void |
putAsciiFile(java.lang.String filename,
java.lang.String content,
java.lang.String separator)
Save an ascii file to the server. |
void |
putBinaryFile(java.lang.String filename,
byte[] content)
Put a binary file to the server from an array of byte. |
void |
putBinaryFile(java.lang.String filename,
byte[] content,
long restart)
Put a binary file to the server from an array of byte with a restarting point |
void |
putBinaryFile(java.lang.String local_file,
java.lang.String remote_file)
Read a file from local hard disk and write to the server. |
void |
putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
FtpObserver observer)
Read a file from local hard disk and write to the server. |
void |
putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
long restart)
Read a file from local hard disk and write to the server with restarting point. |
void |
putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
long restart,
FtpObserver observer)
Read a file from local hard disk and write to the server with restarting point. |
void |
removeDirectory(java.lang.String directory)
Remove a directory in the server |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
|
void |
setDirectory(java.lang.String directory)
Change directory. |
void |
setPassiveModeTransfer(boolean passive)
Set passive transfer mode. |
void |
setPort(int port)
Set port number if the port number of ftp is not 21 |
void |
toParentDirectory()
Change to parent directory. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public FtpBean()
| Method Detail |
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
public void ftpConnect(java.lang.String server,
java.lang.String user,
java.lang.String password)
throws java.io.IOException,
FtpException
server - Name of serveruser - User name for loginpassword - Password for login
public void close()
throws java.io.IOException,
FtpException
public void fileDelete(java.lang.String filename)
throws java.io.IOException,
FtpException
filename - Name of the file to be deleted.
public void fileRename(java.lang.String oldfilename,
java.lang.String newfilename)
throws java.io.IOException,
FtpException
oldfilename - The name of the file to be renamednewfilename - The new name of the file
public java.lang.String getAsciiFile(java.lang.String filename,
java.lang.String separator)
throws java.io.IOException,
FtpException
filename - Name of ASCII file to be getted.separator - The line separator you want in the return String (eg. "\r\n", "\n", "\r")
public java.lang.String getAsciiFile(java.lang.String filename,
java.lang.String separator,
FtpObserver observer)
throws java.io.IOException,
FtpException
filename - Name of ASCII file to be getted.separator - The line separator you want in the return String (eg. "\r\n", "\n", "\r").observer - The observer of the downloading progressFtpObserver
public void putAsciiFile(java.lang.String filename,
java.lang.String content,
java.lang.String separator)
throws java.io.IOException,
FtpException
filename - The name of filecontent - The String content of the fileseparator - Line separator of the content
public byte[] getBinaryFile(java.lang.String filename)
throws java.io.IOException,
FtpException
filename - The name of the binary file to be got.
public byte[] getBinaryFile(java.lang.String filename,
FtpObserver observer)
throws java.io.IOException,
FtpException
filename - The name of the binary file to be got.observer - The observer of the downloading progress.
public byte[] getBinaryFile(java.lang.String filename,
long restart)
throws java.io.IOException,
FtpException
filename - Name of binary file to be getted.restart - Restarting point, ignored if less than or equal to zero.
public byte[] getBinaryFile(java.lang.String filename,
long restart,
FtpObserver observer)
throws java.io.IOException,
FtpException
filename - Name of binary file to be getted.restart - Restarting point, ignored if less than or equal to zero.observer - The FtpObserver which monitor this downloading progressFtpObserver
public void getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile)
throws java.io.IOException,
FtpException
ftpfile - Name of file to be get from the ftp server, can be in full path.localfile - Name of local file to be write, can be in full path.
public void getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
long restart)
throws java.io.IOException,
FtpException
ftpfile - Name of file to be get from the ftp server, can be in full path.localfile - Name of local file to be write, can be in full path.restart - Restarting point
public void getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
FtpObserver observer)
throws java.io.IOException,
FtpException
ftpfile - Name of file to be get from the ftp server, can be in full path.localfile - Name of local file to be write, can be in full path.observer - The FtpObserver which monitor this downloading progressFtpObserver
public void getBinaryFile(java.lang.String ftpfile,
java.lang.String localfile,
long restart,
FtpObserver observer)
throws java.io.IOException,
FtpException
ftpfile - Name of file to be get from the ftp server, can be in full path.localfile - File name of local filerestart - Restarting point, ignored if equal or less than zero.observer - The FtpObserver which monitor this downloading progressFtpObserver
public void putBinaryFile(java.lang.String filename,
byte[] content)
throws java.io.IOException,
FtpException
filename - The name of file.content - The byte array to be written to the server.
public void putBinaryFile(java.lang.String filename,
byte[] content,
long restart)
throws java.io.IOException,
FtpException
filename - The name of file.content - The byte array to be write to the server.restart - The restarting point, ingored if less than or equal to zero.
public void putBinaryFile(java.lang.String local_file,
java.lang.String remote_file)
throws java.io.IOException,
FtpException
local_file - Name of local file, can be in full path.remote_file - Name of file in the ftp server, can be in full path.
public void putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
FtpObserver observer)
throws java.io.IOException,
FtpException
local_file - Name of local file, can be in full path.remote_file - Name of file in the ftp server, can be in full path.observer - The FtpObserver which monitor this uploading progress.
public void putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
long restart)
throws java.io.IOException,
FtpException
local_file - Name of local file, can be in full path.remote_file - Name of file in the ftp server, can be in full path.restart - The restarting point, ignored if less than or greater than zero.
public void putBinaryFile(java.lang.String local_file,
java.lang.String remote_file,
long restart,
FtpObserver observer)
throws java.io.IOException,
FtpException
local_file - Name of local file, can be in full path.remote_file - Name of file in the ftp server, can be in full path.observer - The FtpObserver which monitor this uploading progress
public java.lang.String getDirectory()
throws java.io.IOException,
FtpException
public void setDirectory(java.lang.String directory)
throws java.io.IOException,
FtpException
directory - Name of directory
public void toParentDirectory()
throws java.io.IOException,
FtpException
public FtpListResult getDirectoryContent()
throws java.io.IOException,
FtpException
FtpListResult
public java.lang.String getDirectoryContentAsString()
throws java.io.IOException,
FtpException
public void makeDirectory(java.lang.String directory)
throws java.io.IOException,
FtpException
directory - The name of directory to be made.
public void removeDirectory(java.lang.String directory)
throws java.io.IOException,
FtpException
directory - The name of directory to be removed
public void execute(java.lang.String exec)
throws java.io.IOException,
FtpException
exec - The command to execute.
public java.lang.String getSystemType()
throws java.io.IOException,
FtpException
public int getPort()
public void setPort(int port)
public java.lang.String getServerName()
public java.lang.String getUserName()
public java.lang.String getReply()
public java.lang.String getReplyMessage()
public boolean isPassiveModeTransfer()
public void setPassiveModeTransfer(boolean passive)
passive - Using passive transfer if true.
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||