ftp
Class FtpBean

java.lang.Object
  |
  +--ftp.FtpBean

public class FtpBean
extends java.lang.Object

This bean provide some basic FTP functions.
You can use this bean in some visual development tools (eg. IBM VA) or just include its files 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) Whenever 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.
4) For timeout on creating Socket. if a timeout is being set and operation timeout, a java.io.InterruptedIOException is throw. This is the case for both passive transfer mode and establishment of connection to the server at the beginning. For active transfer mode, timeout is set in the servers ftpd. If there is timeout, the servers ftp software return an error code which causing the bean to throw a ftp.FtpException.

IMPORTANT for using in an Applet:
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 unsigned 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(calvin_tai2000@yahoo.com.hk)


Field Summary
protected static java.lang.String CMD_ACCT
           
protected static java.lang.String CMD_APPE
           
protected static java.lang.String CMD_CDUP
           
protected static java.lang.String CMD_CWD
           
protected static java.lang.String CMD_DELE
           
protected static java.lang.String CMD_LIST
           
protected static java.lang.String CMD_MKD
           
protected static java.lang.String CMD_PASS
           
protected static java.lang.String CMD_PASV
           
protected static java.lang.String CMD_PORT
           
protected static java.lang.String CMD_PWD
           
protected static java.lang.String CMD_QUIT
           
protected static java.lang.String CMD_REST
           
protected static java.lang.String CMD_RETR
           
protected static java.lang.String CMD_RMD
           
protected static java.lang.String CMD_RNFR
           
protected static java.lang.String CMD_RNTO
           
protected static java.lang.String CMD_SITE
           
protected static java.lang.String CMD_STOR
           
protected static java.lang.String CMD_SYST
           
protected static java.lang.String CMD_TYPE
           
protected static java.lang.String CMD_USER
           
protected static java.lang.String FTP_INIT
           
protected static java.lang.String REPLY_PER_NEG
           
protected static java.lang.String REPLY_POS_CMP
           
protected static java.lang.String REPLY_POS_INT
           
protected static java.lang.String REPLY_POS_PRE
           
protected static java.lang.String REPLY_TRA_NEG
           
protected static java.lang.String REPLY_UNDEF
           
 
Constructor Summary
FtpBean()
          Constructor
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void appendAsciiFile(java.lang.String filename, java.lang.String content, java.lang.String separator)
          Append an ascii file to the server.
 void appendBinaryFile(java.lang.String filename)
          Read a file from local hard disk and append a file on the server.
 void appendBinaryFile(java.lang.String local_file, java.lang.String remote_file)
          Read a file from local hard disk and append to the server with restarting point.
 void appendBinaryFile(java.lang.String local_file, java.lang.String remote_file, ftp.FtpObserver observer)
          Read a file from local hard disk and append to the server with restarting point.
 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)
          Connect to Ftp server and login.
 void ftpConnect(java.lang.String server, java.lang.String user, java.lang.String password)
          Connect to Ftp server and login.
 void ftpConnect(java.lang.String server, java.lang.String user, java.lang.String password, java.lang.String acct)
          Connect to FTP server and login.
 java.lang.String getAcctInfo()
          Return the account information.
 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, ftp.FtpObserver observer)
          Get an ASCII file from the server and return as String.
 void getAsciiFile(java.lang.String ftpfile, java.lang.String localfile, java.lang.String separator)
          Get an ascii file from the server and write to local file system.
 void getAsciiFile(java.lang.String ftpfile, java.lang.String localfile, java.lang.String separator, ftp.FtpObserver observer)
          Get an ascii file from the server and write to local file system.
 byte[] getBinaryFile(java.lang.String filename)
          Get a binary file and return a byte array.
 byte[] getBinaryFile(java.lang.String filename, ftp.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, ftp.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, ftp.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, ftp.FtpObserver observer)
          Read from a ftp file and restart at a specific point.
 java.lang.String getDirectory()
          Get current directory name.
 ftp.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.
 int getSocketTimeout()
          Get timeout when creating socket.
 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, ftp.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, ftp.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 setSocketTimeout(int timeout)
          Set timeout when creating a socket.
 void toParentDirectory()
          Change to parent directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FTP_INIT

protected static final java.lang.String FTP_INIT
See Also:
Constant Field Values

CMD_ACCT

protected static final java.lang.String CMD_ACCT
See Also:
Constant Field Values

CMD_APPE

protected static final java.lang.String CMD_APPE
See Also:
Constant Field Values

CMD_CWD

protected static final java.lang.String CMD_CWD
See Also:
Constant Field Values

CMD_CDUP

protected static final java.lang.String CMD_CDUP
See Also:
Constant Field Values

CMD_DELE

protected static final java.lang.String CMD_DELE
See Also:
Constant Field Values

CMD_MKD

protected static final java.lang.String CMD_MKD
See Also:
Constant Field Values

CMD_PASV

protected static final java.lang.String CMD_PASV
See Also:
Constant Field Values

CMD_PASS

protected static final java.lang.String CMD_PASS
See Also:
Constant Field Values

CMD_PORT

protected static final java.lang.String CMD_PORT
See Also:
Constant Field Values

CMD_PWD

protected static final java.lang.String CMD_PWD
See Also:
Constant Field Values

CMD_QUIT

protected static final java.lang.String CMD_QUIT
See Also:
Constant Field Values

CMD_RMD

protected static final java.lang.String CMD_RMD
See Also:
Constant Field Values

CMD_REST

protected static final java.lang.String CMD_REST
See Also:
Constant Field Values

CMD_RETR

protected static final java.lang.String CMD_RETR
See Also:
Constant Field Values

CMD_RNTO

protected static final java.lang.String CMD_RNTO
See Also:
Constant Field Values

CMD_RNFR

protected static final java.lang.String CMD_RNFR
See Also:
Constant Field Values

CMD_SITE

protected static final java.lang.String CMD_SITE
See Also:
Constant Field Values

CMD_STOR

protected static final java.lang.String CMD_STOR
See Also:
Constant Field Values

CMD_SYST

protected static final java.lang.String CMD_SYST
See Also:
Constant Field Values

CMD_USER

protected static final java.lang.String CMD_USER
See Also:
Constant Field Values

CMD_TYPE

protected static final java.lang.String CMD_TYPE
See Also:
Constant Field Values

CMD_LIST

protected static final java.lang.String CMD_LIST
See Also:
Constant Field Values

REPLY_POS_PRE

protected static final java.lang.String REPLY_POS_PRE
See Also:
Constant Field Values

REPLY_POS_CMP

protected static final java.lang.String REPLY_POS_CMP
See Also:
Constant Field Values

REPLY_POS_INT

protected static final java.lang.String REPLY_POS_INT
See Also:
Constant Field Values

REPLY_TRA_NEG

protected static final java.lang.String REPLY_TRA_NEG
See Also:
Constant Field Values

REPLY_PER_NEG

protected static final java.lang.String REPLY_PER_NEG
See Also:
Constant Field Values

REPLY_UNDEF

protected static final java.lang.String REPLY_UNDEF
See Also:
Constant Field Values
Constructor Detail

FtpBean

public FtpBean()
Constructor

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

ftpConnect

public void ftpConnect(java.lang.String server,
                       java.lang.String user)
                throws java.io.IOException,
                       FtpException
Connect to Ftp server and login.

Parameters:
server - Name of server
user - User name for login
Throws:
FtpException - if a ftp error occur (eg. Login fail in this case).
java.io.IOException - if an I/O error occur

ftpConnect

public void ftpConnect(java.lang.String server,
                       java.lang.String user,
                       java.lang.String password)
                throws java.io.IOException,
                       FtpException
Connect to Ftp server and login.

Parameters:
server - Name of server
user - User name for login
password - Password for login
Throws:
FtpException - if a ftp error occur (eg. Login fail in this case).
java.io.IOException - if an I/O error occur

ftpConnect

public void ftpConnect(java.lang.String server,
                       java.lang.String user,
                       java.lang.String password,
                       java.lang.String acct)
                throws java.io.IOException,
                       FtpException
Connect to FTP server and login.

Parameters:
server - Name of server
user - User name for login
password - Password for login
acct - account information
Throws:
FtpException - if a ftp error occur (eg. Login fail in this case).
java.io.IOException - if an I/O error occur

close

public void close()
           throws java.io.IOException,
                  FtpException
Close FTP connection.

Throws:
java.io.IOException - if an I/O error occur
FtpException - if a ftp error occur

fileDelete

public void fileDelete(java.lang.String filename)
                throws java.io.IOException,
                       FtpException
Delete a file at the FTP server.

Parameters:
filename - Name of the file to be deleted.
Throws:
FtpException - if a ftp error occur. (eg. no such file in this case)
java.io.IOException - if an I/O error occur.

fileRename

public void fileRename(java.lang.String oldfilename,
                       java.lang.String newfilename)
                throws java.io.IOException,
                       FtpException
Rename a file at the FTP server.

Parameters:
oldfilename - The name of the file to be renamed
newfilename - The new name of the file
Throws:
FtpException - if a ftp error occur. (eg. A file named the new file name already in this case.)
java.io.IOException - if an I/O error occur.

getAsciiFile

public java.lang.String getAsciiFile(java.lang.String filename,
                                     java.lang.String separator)
                              throws java.io.IOException,
                                     FtpException
Get an ASCII file from the server and return as String.

Parameters:
filename - Name of ASCII file to be getted.
separator - The line separator you want in the return String (eg. "\r\n", "\n", "\r")
Returns:
The Ascii content of the file. It uses parameter 'separator' as the line separator.
Throws:
FtpException - if a ftp error occur. (eg. no such file in this case)
java.io.IOException - if an I/O error occur.

getAsciiFile

public java.lang.String getAsciiFile(java.lang.String filename,
                                     java.lang.String separator,
                                     ftp.FtpObserver observer)
                              throws java.io.IOException,
                                     FtpException
Get an ASCII file from the server and return as String.

Parameters:
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 progress
Returns:
The Ascii content of the file. It uses parameter 'separator' as the line separator.
Throws:
FtpException - if a ftp error occur. (eg. no such file in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpObserver

getAsciiFile

public void getAsciiFile(java.lang.String ftpfile,
                         java.lang.String localfile,
                         java.lang.String separator)
                  throws java.io.IOException,
                         FtpException
Get an ascii file from the server and write to local file system.

Parameters:
ftpfile - Name of ascii file in the server side.
localfile - Name of ascii file in the local file system.
separator - The line separator you want in the local ascii file (eg. "\r\n", "\n", "\r").
Throws:
FtpException - if a ftp error occur. (eg. no such file in this case)
java.io.IOException - if an I/O error occur.

getAsciiFile

public void getAsciiFile(java.lang.String ftpfile,
                         java.lang.String localfile,
                         java.lang.String separator,
                         ftp.FtpObserver observer)
                  throws java.io.IOException,
                         FtpException
Get an ascii file from the server and write to local file system.

Parameters:
ftpfile - Name of ascii file in the server side.
localfile - Name of ascii file in the local file system.
separator - The line separator you want in the local ascii file (eg. "\r\n", "\n", "\r").
observer - The observer of the downloading progress.
Throws:
FtpException - if a ftp error occur. (eg. no such file in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpObserver

appendAsciiFile

public void appendAsciiFile(java.lang.String filename,
                            java.lang.String content,
                            java.lang.String separator)
                     throws java.io.IOException,
                            FtpException
Append an ascii file to the server.
Remark:
this method convert the line separator of the String content to
NVT-ASCII format line separator "\r\n". Then the ftp daemon will
convert the NVT-ASCII format line separator into its system line separator.

Parameters:
filename - The name of file
content - The String content of the file
separator - Line separator of the content
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

putAsciiFile

public void putAsciiFile(java.lang.String filename,
                         java.lang.String content,
                         java.lang.String separator)
                  throws java.io.IOException,
                         FtpException
Save an ascii file to the server.
Remark:
this method convert the line separator of the String content to
NVT-ASCII format line separator "\r\n". Then the ftp daemon will
convert the NVT-ASCII format line separator into its system line separator.

Parameters:
filename - The name of file
content - The String content of the file
separator - Line separator of the content
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public byte[] getBinaryFile(java.lang.String filename)
                     throws java.io.IOException,
                            FtpException
Get a binary file and return a byte array.

Parameters:
filename - The name of the binary file to be got.
Returns:
An array of byte of the content of the binary file.
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public byte[] getBinaryFile(java.lang.String filename,
                            ftp.FtpObserver observer)
                     throws java.io.IOException,
                            FtpException
Get a binary file and return a byte array.

Parameters:
filename - The name of the binary file to be got.
observer - The observer of the downloading progress.
Returns:
An array of byte of the content of the binary file.
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public byte[] getBinaryFile(java.lang.String filename,
                            long restart)
                     throws java.io.IOException,
                            FtpException
Get a binary file at a restarting point. Return null if restarting point is less than zero.

Parameters:
filename - Name of binary file to be getted.
restart - Restarting point, ignored if less than or equal to zero.
Returns:
An array of byte of the content of the binary file.
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public byte[] getBinaryFile(java.lang.String filename,
                            long restart,
                            ftp.FtpObserver observer)
                     throws java.io.IOException,
                            FtpException
Get a binary file at a restarting point. Return null if restarting point is less than zero.

Parameters:
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 progress
Returns:
An array of byte of the content of the binary file.
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpObserver

getBinaryFile

public void getBinaryFile(java.lang.String ftpfile,
                          java.lang.String localfile)
                   throws java.io.IOException,
                          FtpException
Read file from ftp server and write to a file in local hard disk. This method is much faster than those method which return a byte array
if the network is fast enough.

Remark:
Cannot be used in unsigned applet.

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public void getBinaryFile(java.lang.String ftpfile,
                          java.lang.String localfile,
                          long restart)
                   throws java.io.IOException,
                          FtpException
Read file from ftp server and write to a file in local hard disk. This method is much faster than those method which return a byte array
if the network is fast enough.

Remark:
Cannot be used in unsigned applet.

Parameters:
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
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.

getBinaryFile

public void getBinaryFile(java.lang.String ftpfile,
                          java.lang.String localfile,
                          ftp.FtpObserver observer)
                   throws java.io.IOException,
                          FtpException
Read file from ftp server and write to a file in local hard disk. This method is much faster than those method which return a byte array
if the network is fast enough.

Remark:
Cannot be used in unsigned applet.

Parameters:
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 progress
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpObserver

getBinaryFile

public void getBinaryFile(java.lang.String ftpfile,
                          java.lang.String localfile,
                          long restart,
                          ftp.FtpObserver observer)
                   throws java.io.IOException,
                          FtpException
Read from a ftp file and restart at a specific point. This method is much faster than those method which return a byte array
if the network is fast enough.
Remark:
Cannot be used in unsigned applet.

Parameters:
ftpfile - Name of file to be get from the ftp server, can be in full path.
localfile - File name of local file
restart - Restarting point, ignored if equal or less than zero.
observer - The FtpObserver which monitor this downloading progress
Throws:
FtpException - if a ftp error occur. (eg. No such file in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpObserver

putBinaryFile

public void putBinaryFile(java.lang.String filename,
                          byte[] content)
                   throws java.io.IOException,
                          FtpException
Put a binary file to the server from an array of byte.

Parameters:
filename - The name of file.
content - The byte array to be written to the server.
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

putBinaryFile

public void putBinaryFile(java.lang.String filename,
                          byte[] content,
                          long restart)
                   throws java.io.IOException,
                          FtpException
Put a binary file to the server from an array of byte with a restarting point

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

putBinaryFile

public void putBinaryFile(java.lang.String local_file,
                          java.lang.String remote_file)
                   throws java.io.IOException,
                          FtpException
Read a file from local hard disk and write to the server.
Remark:

Cannot be used in unsigned applet.

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

putBinaryFile

public void putBinaryFile(java.lang.String local_file,
                          java.lang.String remote_file,
                          ftp.FtpObserver observer)
                   throws java.io.IOException,
                          FtpException
Read a file from local hard disk and write to the server.
Remark:

Cannot be used in unsigned applet.

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

putBinaryFile

public void putBinaryFile(java.lang.String local_file,
                          java.lang.String remote_file,
                          long restart)
                   throws java.io.IOException,
                          FtpException
Read a file from local hard disk and write to the server with restarting point. Remark:
Cannot be used in unsigned applet.

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

putBinaryFile

public void putBinaryFile(java.lang.String local_file,
                          java.lang.String remote_file,
                          long restart,
                          ftp.FtpObserver observer)
                   throws java.io.IOException,
                          FtpException
Read a file from local hard disk and write to the server with restarting point. Remark:
Cannot be used in unsigned applet.

Parameters:
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
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

appendBinaryFile

public void appendBinaryFile(java.lang.String filename)
                      throws java.io.IOException,
                             FtpException
Read a file from local hard disk and append a file on the server. Remark:
Cannot be used in unsigned applet.

Parameters:
filename - Name of local file and remote file.
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

appendBinaryFile

public void appendBinaryFile(java.lang.String local_file,
                             java.lang.String remote_file)
                      throws java.io.IOException,
                             FtpException
Read a file from local hard disk and append to the server with restarting point. Remark:
Cannot be used in unsigned applet.

Parameters:
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.
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

appendBinaryFile

public void appendBinaryFile(java.lang.String local_file,
                             java.lang.String remote_file,
                             ftp.FtpObserver observer)
                      throws java.io.IOException,
                             FtpException
Read a file from local hard disk and append to the server with restarting point. Remark:
Cannot be used in unsigned applet.

Parameters:
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
Throws:
FtpException - if a ftp error occur. (eg. permission denied)
java.io.IOException - if an I/O error occur.

getDirectory

public java.lang.String getDirectory()
                              throws java.io.IOException,
                                     FtpException
Get current directory name.

Returns:
The name of the current directory.
Throws:
FtpException - if a ftp error occur.
java.io.IOException - if an I/O error occur.

setDirectory

public void setDirectory(java.lang.String directory)
                  throws java.io.IOException,
                         FtpException
Change directory.

Parameters:
directory - Name of directory
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

toParentDirectory

public void toParentDirectory()
                       throws java.io.IOException,
                              FtpException
Change to parent directory.

Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

getDirectoryContent

public ftp.FtpListResult getDirectoryContent()
                                      throws java.io.IOException,
                                             FtpException
Get the content of current directory

Returns:
A FtpListResult object, return null if it is not connected.
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.
See Also:
FtpListResult

getDirectoryContentAsString

public java.lang.String getDirectoryContentAsString()
                                             throws java.io.IOException,
                                                    FtpException
Get the content of current directory.

Returns:
A list of directories, files and links in the current directory.
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

makeDirectory

public void makeDirectory(java.lang.String directory)
                   throws java.io.IOException,
                          FtpException
Make a directory in the server.

Parameters:
directory - The name of directory to be made.
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

removeDirectory

public void removeDirectory(java.lang.String directory)
                     throws java.io.IOException,
                            FtpException
Remove a directory in the server

Parameters:
directory - The name of directory to be removed
Throws:
FtpException - if a ftp error occur. (eg. permission denied in this case)
java.io.IOException - if an I/O error occur.

execute

public void execute(java.lang.String exec)
             throws java.io.IOException,
                    FtpException
Execute a command using ftp. e.g. chmod 700 file

Parameters:
exec - The command to execute.
Throws:
FtpException - if a ftp error occur. (eg. command not understood)
java.io.IOException - if an I/O error occur.

getSystemType

public java.lang.String getSystemType()
                               throws java.io.IOException,
                                      FtpException
Get the type of operating system of the server. Return null if it is not currently connected to any ftp server.

Returns:
Name of the operating system.
java.io.IOException
FtpException

getPort

public int getPort()
Return the port number


setPort

public void setPort(int port)
Set port number if the port number of ftp is not 21


setSocketTimeout

public void setSocketTimeout(int timeout)
                      throws java.net.SocketException
Set timeout when creating a socket. This include trying to connect to the ftp server at the beginnig and trying to connect to the server in order to establish a data connection.

Parameters:
timeout - Timeout in milliseconds, 0 means infinity.
java.net.SocketException

getSocketTimeout

public int getSocketTimeout()
                     throws java.net.SocketException
Get timeout when creating socket.

Returns:
Timeout for creating socket in milliseconds, 0 means infinity.
java.net.SocketException

getAcctInfo

public java.lang.String getAcctInfo()
Return the account information. Return "" if it is not connected to any server.


getServerName

public java.lang.String getServerName()
Return the server name. Return "" if it is not connected to any server.


getUserName

public java.lang.String getUserName()
Return the user name. Return "" if it is not connected to any server.


getReply

public java.lang.String getReply()
Get reply of the last command.

Returns:
Reply of the last comomand
for example: 250 CWD command successful

getReplyMessage

public java.lang.String getReplyMessage()
Get reply message of the last command.

Returns:
Reply message of the last command
for example:
250-Please read the file README
250-it was last modified on Wed Feb 10 21:51:00 1999 - 268 days ago

isPassiveModeTransfer

public boolean isPassiveModeTransfer()
Return true if it is using passive transfer mode.


setPassiveModeTransfer

public void setPassiveModeTransfer(boolean passive)
Set passive transfer mode. Default is true.

Parameters:
passive - Using passive transfer if true.