Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT internal-b00

java.net
Class FtpClient

java.lang.Object
  extended by java.net.FtpClient

public class FtpClient
extends Object

A class that implements the FTP protocol according to RFCs 959, 2228, 2389, 2428, 3659, 4217. Which includes support for FTP over SSL/TLS (aka ftps). FtpClient provides all the functionality of a typical FTP client, like storing or retrieving files, listing or creating directories. A typical usage would consist of connecting the client to the server, log in, issue a few commands then logout. Here is a code example:

 FtpClient cl = FtpClient.create();
 if (cl.connect("ftp.gnu.org") &&
     cl.login("anonymous", "john.doe@mydomain.com".toCharArray())) {
     cl.changeDirectory("pub/gnu");
     Iterator<FtpFile> dir = cl.listFiles();
     while (dir.hasNext()) {
         FtpFile f = dir.next();
         System.err.println(f.getName());
     }
     cl.logout();
 }
 

It should be noted that this is not a thread-safe API, as it wouldn't make too much sense, due to the very sequential nature of FTP, to provide a client able to be manipulated from multiple threads.

Since:
1.7

Nested Class Summary
static class FtpClient.TransferMode
           
static class FtpClient.TransferType
           
 
Constructor Summary
protected FtpClient()
          Creates an instance of FtpClient.
 
Method Summary
 boolean abort()
          sends the ABOR command to the server.
 boolean allocate(long size)
          Sends the "Allocate" (ALLO) command to the server telling it to pre-allocate the specified number of bytes for the next transfer.
 boolean appendFile(String name, InputStream local)
          Sends the APPE command to the server in order to transfer a data stream passed in argument and append it to the content of the specified remote file.
 boolean changeDirectory(String remoteDirectory)
          Changes to a specific directory on a remote FTP server
 boolean changeToParentDirectory()
          Changes to the parent directory, sending the CDUP command to the server.
 boolean clearTLS()
          Sends a CCC command followed by a PROT C command to the server terminating an encrypted session and reverting back to a non crypted transmission.
 boolean completePending()
          Some methods do not wait until completion before returning, so this method can be called to wait until completion.
 void connect(InetSocketAddress dest)
          Connects the FtpClient to the specified destination.
 void connect(String dest)
          Connects the FtpClient to the specified destination server using the default FTP port.
 void connect(String dest, int port)
          Connects the FtpClient to the specified destination server using the specified port.
static FtpClient create()
          Creates an instance of FtpClient.
static FtpClient create(InetSocketAddress dest)
          Creates an instance of FtpClient and connects it to the specified address.
static FtpClient create(String dest)
          Creates an instance of FtpClient and connects it to the specified host on the default FTP port.
static int defaultPort()
          Returns the default FTP port number.
 boolean deleteFile(String name)
          Deletes a file on the server.
 int getConnectTimeout()
          Returns the current connection timeout value.
 List<String> getFeatures()
          Sends the FEAT command to the server and returns the list of supported features in the form of strings.
 boolean getFile(String name, OutputStream local)
          Retrieves a file from the ftp server and writes it to the specified OutputStream.
 InputStream getFileStream(String name)
          Retrieves a file from the ftp server, using the RETR command, and returns the InputStream from* the established data connection.
 String getHelp(String cmd)
          Sends the HELP command to the server, with an optional command, like SITE, and returns the text sent back by the server.
 String getLastFileName()
          Returns, when available, the remote name of the last transfered file.
 Date getLastModified(String path)
          Issues the MDTM [path] command to the server to get the modification time of a specific file on the server.
 FtpReplyCode getLastReplyCode()
          Returns the last reply code sent by the server.
 String getLastResponseString()
          Returns the last response string sent by the server.
 long getLastTransferSize()
          Returns, when available, the size of the latest started transfer.
 Proxy getProxy()
          Get the proxy of this FtpClient
 int getReadTimeout()
          Returns the current read timeout value.
 long getSize(String path)
          Issues the SIZE [path] command to the server to get the size of a specific file on the server.
 String getStatus(String name)
          Sends the STAT command to the server.
 String getSystem()
          Sends a SYST (System) command to the server and returns the String sent back by the server describing the operating system at the server.
 FtpClient.TransferMode getTransferMode()
          Gets the current transfer mode.
 String getWelcomeMsg()
          Returns the Welcome string the server sent during initial connection.
 String getWorkingDirectory()
          Returns the server current working directory, or null if the PWD command failed.
 boolean isConnected()
          Tests whether this client is connected or not to a server.
 boolean isLoggedIn()
          Checks whether the client is logged in to the server or not.
 InputStream list(String path)
          Issues a LIST command to the server to get the current directory listing, and returns the InputStream from the data connection.
 Iterator<FtpFile> listFiles(String path)
          Issues a MLSD command to the server to get the specified directory listing and applies the current parser to create an Iterator of java.net.ftp.FtpFile.
 boolean login(String user, char[] password)
          Attempts to log on the server with the specified user name and password.
 boolean login(String user, char[] password, String account)
          Attempts to log on the server with the specified user name, password and account name.
 void logout()
          Logs out the current user.
 boolean makeDirectory(String name)
          Creates a new directory on the server.
 InputStream nameList(String path)
          Issues a NLST path command to server to get the specified directory content.
 boolean noop()
          Sends a No-operation command.
 boolean putFile(String name, InputStream local)
          Transfers a file from the client to the server (aka a put) by sending the STOR or STOU command, depending on the unique argument.
 boolean putFile(String name, InputStream local, boolean unique)
          Transfers a file from the client to the server (aka a put) by sending the STOR command.
 OutputStream putFileStream(String name)
          Transfers a file from the client to the server (aka a put) by sending the STOR command, and returns the OutputStream from the established data connection.
 OutputStream putFileStream(String name, boolean unique)
          Transfers a file from the client to the server (aka a put) by sending the STOR or STOU command, depending on the unique argument, and returns the OutputStream from the established data connection.
 void reInit()
          Reinitializes the USER parameters on the FTP server
 boolean removeDirectory(String name)
          Removes a directory on the server.
 boolean rename(String from, String to)
          Renames a file on the server.
 FtpClient setActiveMode()
          Sets the transfer mode to active.
 FtpClient setAsciiType()
          Changes the current transfer type to ascii.
 FtpClient setBinaryType()
          Changes the current transfer type to binary.
 FtpClient setConnectTimeout(int timeout)
          Sets the timeout value to use when connecting to the server,
 void setFileParser(FtpFileParser p)
          Sets the parser used to handle the directory output to the specified one.
 FtpClient setPassiveMode()
          Set the transfer mode to passive.
 FtpClient setProxy(Proxy p)
          Set the Proxy to be used.
 FtpClient setReadTimeout(int timeout)
          Sets the timeout value to use when reading from the server,
 void setRestartOffset(long offset)
          Sets the restart offset to the specified value.
 FtpClient setType(FtpClient.TransferType type)
          Changes the transfer type (binary, ascii, ebcdic) and issue the proper command (e.g.
 boolean siteCmd(String cmd)
          Sends the SITE command to the server.
 boolean structureMount(String struct)
          Sends the "Structure Mount" (SMNT) command to the server.
 boolean useGSSAPI()
          Attempts to use Kerberos GSSAPI as an authentication mechanism with the ftp server.
 boolean useTLS()
          Attempts to switch to a secure, encrypted connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FtpClient

protected FtpClient()
Creates an instance of FtpClient. The client is not connected to any server yet.

Method Detail

defaultPort

public static int defaultPort()
Returns the default FTP port number.

Returns:
the port number.

create

public static FtpClient create()
Creates an instance of FtpClient. The client is not connected to any server yet.


create

public static FtpClient create(InetSocketAddress dest)
                        throws IOException
Creates an instance of FtpClient and connects it to the specified address.

Parameters:
dest - the InetSocketAddress to connect to.
Returns:
The created FtpClient
Throws:
IOException - if the connection fails

create

public static FtpClient create(String dest)
                        throws IOException
Creates an instance of FtpClient and connects it to the specified host on the default FTP port.

Parameters:
dest - the String containing the name of the host to connect to.
Returns:
The created FtpClient
Throws:
IOException - if the connection fails.

setPassiveMode

public FtpClient setPassiveMode()
Set the transfer mode to passive. In that mode, data connections are established by having the client connect to the server. This is the recommended default mode as it will work best through firewalls and NATs.

Returns:
This FtpClient
See Also:
setActiveMode()

setActiveMode

public FtpClient setActiveMode()
Sets the transfer mode to active. In that mode, data connections are established by having the server connect to the client. This used to be the default mode for ftp clients, but can be problematic now that most machines are behind firewalls and NATs.

Returns:
This FtpClient
See Also:
setPassiveMode()

getTransferMode

public FtpClient.TransferMode getTransferMode()
Gets the current transfer mode.

Returns:
the current TransferMode

setConnectTimeout

public FtpClient setConnectTimeout(int timeout)
Sets the timeout value to use when connecting to the server,

Parameters:
timeout - the timeout value, in milliseconds, to use for the connect operation. A value of zero or less, means use the default timeout.
Returns:
This FtpClient

getConnectTimeout

public int getConnectTimeout()
Returns the current connection timeout value.

Returns:
the value, in milliseconds, of the current connect timeout.
See Also:
setConnectTimeout(int)

setReadTimeout

public FtpClient setReadTimeout(int timeout)
Sets the timeout value to use when reading from the server,

Parameters:
timeout - the timeout value, in milliseconds, to use for the read operation. A value of zero or less, means use the default timeout.
Returns:
This FtpClient

getReadTimeout

public int getReadTimeout()
Returns the current read timeout value.

Returns:
the value, in milliseconds, of the current read timeout.
See Also:
setReadTimeout(int)

setProxy

public FtpClient setProxy(Proxy p)
                   throws IOException
Set the Proxy to be used.

Parameters:
p - the Proxy to use, or null for no proxy.
Returns:
This FtpClient
Throws:
IOException - if the FtpClient is already connected

getProxy

public Proxy getProxy()
Get the proxy of this FtpClient

Returns:
the Proxy, this client is using, or null if none is used.
See Also:
setProxy(Proxy)

isConnected

public boolean isConnected()
Tests whether this client is connected or not to a server.

Returns:
true if the client is connected.

connect

public void connect(String dest)
             throws IOException
Connects the FtpClient to the specified destination server using the default FTP port.

Parameters:
dest - the name of the destination server
Throws:
IOException - if connection failed.

connect

public void connect(String dest,
                    int port)
             throws IOException
Connects the FtpClient to the specified destination server using the specified port.

Parameters:
dest - the name of the destination server.
port - the port number of the destination server.
Throws:
IOException - if connection failed.

connect

public void connect(InetSocketAddress dest)
             throws IOException
Connects the FtpClient to the specified destination.

Parameters:
dest - the address of the destination server
Throws:
IOException - if connection failed.

login

public boolean login(String user,
                     char[] password)
              throws IOException
Attempts to log on the server with the specified user name and password.

Parameters:
user - The user name
password - The password for that user
Returns:
true if the login was successful.
Throws:
IOException - if an error occured during the transmission

login

public boolean login(String user,
                     char[] password,
                     String account)
              throws IOException
Attempts to log on the server with the specified user name, password and account name.

Parameters:
user - The user name
password - The password for that user.
account - The account name for that user.
Returns:
true if the login was successful.
Throws:
IOException - if an error occurs during the transmission.

logout

public void logout()
Logs out the current user. This is in effect terminates the current session and the connection to the server will be closed.


isLoggedIn

public boolean isLoggedIn()
Checks whether the client is logged in to the server or not.

Returns:
true if the client has already completed a login.

changeDirectory

public boolean changeDirectory(String remoteDirectory)
                        throws IOException
Changes to a specific directory on a remote FTP server

Parameters:
remoteDirectory - path of the directory to CD to.
Returns:
true if the operation was successful.
Throws:
FtpProtocolException
IOException

changeToParentDirectory

public boolean changeToParentDirectory()
                                throws IOException
Changes to the parent directory, sending the CDUP command to the server.

Returns:
true if the command was successful.
Throws:
IOException

getWorkingDirectory

public String getWorkingDirectory()
                           throws IOException
Returns the server current working directory, or null if the PWD command failed.

Returns:
a String containing the current working directory, or null
Throws:
IOException

setRestartOffset

public void setRestartOffset(long offset)
Sets the restart offset to the specified value. That value will be sent through a REST command to server before a file transfer and has the effect of resuming a file transfer from the specified point. After a transfer the restart offset is set back to zero.

Parameters:
offset - the offset in the remote file at which to start the next transfer. This must be a value greater than or equal to zero.
Throws:
IllegalArgumentException - if the offset is negative.

getFile

public boolean getFile(String name,
                       OutputStream local)
                throws IOException
Retrieves a file from the ftp server and writes it to the specified OutputStream. If the restart offset was set, then a REST command will be sent before the RETR in order to restart the tranfer from the specified offset. The OutputStream is not closed by this method at the end of the transfer.

Parameters:
name - a String containing the name of the file to retreive from the server.
local - the OutputStream the file should be written to.
Throws:
IOException - if the transfer fails.

getFileStream

public InputStream getFileStream(String name)
                          throws IOException
Retrieves a file from the ftp server, using the RETR command, and returns the InputStream from* the established data connection. completePending() has to be called once the application is done reading from the returned stream.

Parameters:
name - the name of the remote file
Returns:
the InputStream from the data connection, or null if the command was unsuccessful.
Throws:
IOException - if an error occured during the transmission.

putFileStream

public OutputStream putFileStream(String name)
                           throws IOException
Transfers a file from the client to the server (aka a put) by sending the STOR command, and returns the OutputStream from the established data connection. A new file is created at the server site if the file specified does not already exist. completePending() has to be called once the application is finished writing to the returned stream.

Parameters:
name - the name of the remote file to write.
Returns:
the OutputStream from the data connection or null if the command was unsuccessful.
Throws:
IOException - if an error occured during the transmission.

putFileStream

public OutputStream putFileStream(String name,
                                  boolean unique)
                           throws IOException
Transfers a file from the client to the server (aka a put) by sending the STOR or STOU command, depending on the unique argument, and returns the OutputStream from the established data connection. completePending() has to be called once the application is finished writing to the stream. A new file is created at the server site if the file specified does not already exist. If unique is set to true, the resultant file is to be created under a name unique to that directory, meaning it will not overwrite an existing file, instead the server will generate a new, unique, file name. The name of the remote file can be retrieved, after completion of the transfer, by calling getLastFileName().

Parameters:
name - the name of the remote file to write.
unique - true if the remote files should be unique, in which case the STOU command will be used.
Returns:
the OutputStream from the data connection or null if the command was unsuccessful.
Throws:
IOException - if an error occured during the transmission.

putFile

public boolean putFile(String name,
                       InputStream local)
                throws IOException
Transfers a file from the client to the server (aka a put) by sending the STOR or STOU command, depending on the unique argument. The content of the InputStream passed in argument is written into the remote file, overwriting any existing data. A new file is created at the server site if the file specified does not already exist. If unique is set to true, the resultant file is to be created under a name unique to that directory, meaning it will not overwrite an existing file, instead the server will generate a new, unique, file name. The name of the remote file can be retrieved, after completion of the transfer, by calling getLastFileName().

Parameters:
name - the name of the remote file to write.
local - the InputStream that points to the data to transfer.
Returns:
true if the transfer was successful.
Throws:
IOException - if an error occured during the transmission.

putFile

public boolean putFile(String name,
                       InputStream local,
                       boolean unique)
                throws IOException
Transfers a file from the client to the server (aka a put) by sending the STOR command. The content of the InputStream passed in argument is written into the remote file, overwriting any existing data. A new file is created at the server site if the file specified does not already exist.

Parameters:
name - the name of the remote file to write.
local - the InputStream that points to the data to transfer.
unique - true if the remote file should be unique (i.e. not already existing), false otherwise.
Returns:
true if the transfer was successful.
Throws:
IOException - if an error occured during the transmission.
See Also:
getLastFileName()

appendFile

public boolean appendFile(String name,
                          InputStream local)
                   throws IOException
Sends the APPE command to the server in order to transfer a data stream passed in argument and append it to the content of the specified remote file.

Parameters:
name - A String containing the name of the remote file to append to.
local - The InputStream providing access to the data to be appended.
Returns:
true if the transfer was successful.
Throws:
IOException - if an error occured during the transmission.

rename

public boolean rename(String from,
                      String to)
               throws IOException
Renames a file on the server.

Parameters:
from - the name of the file being renamed
to - the new name for the file
Throws:
IOException - if the command fails

deleteFile

public boolean deleteFile(String name)
                   throws IOException
Deletes a file on the server.

Parameters:
name - a String containing the name of the file to delete.
Returns:
true if the command was successful
Throws:
IOException - if an error occured during the exchange

makeDirectory

public boolean makeDirectory(String name)
                      throws IOException
Creates a new directory on the server.

Parameters:
name - a String containing the name of the directory to create.
Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during the exchange

removeDirectory

public boolean removeDirectory(String name)
                        throws IOException
Removes a directory on the server.

Parameters:
name - a String containing the name of the directory to remove.
Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during the exchange.

noop

public boolean noop()
             throws IOException
Sends a No-operation command. It's useful for testing the connection status or as a keep alive mechanism.

Throws:
FtpProtocolException - if the command fails
IOException

getStatus

public String getStatus(String name)
                 throws IOException
Sends the STAT command to the server. This can be used while a data connection is open to get a status on the current transfer, in that case the parameter should be null. If used between file transfers, it may have a pathname as argument in which case it will work as the LIST command except no data connection will be created.

Parameters:
name - an optional String containing the pathname the STAT command should apply to.
Returns:
the response from the server or null if the command failed.
Throws:
IOException - if an error occured during the transmission.

getFeatures

public List<String> getFeatures()
                         throws IOException
Sends the FEAT command to the server and returns the list of supported features in the form of strings. The features are the supported commands, like AUTH TLS, PROT or PASV. See the RFCs for a complete list. Note that not all FTP servers support that command, in which case the method will return null

Returns:
a List of Strings describing the supported additional features, or null if the command is not supported.
Throws:
IOException - if an error occurs during the transmission.

abort

public boolean abort()
              throws IOException
sends the ABOR command to the server. It tells the server to stop the previous command or transfer.

Returns:
true if the command was successful.
Throws:
IOException - if an error occured during the transmission.

completePending

public boolean completePending()
                        throws IOException
Some methods do not wait until completion before returning, so this method can be called to wait until completion. This is typically the case with commands that trigger a transfer like getFileStream(String). So this method should be called before accessing information related to such a command.

This method will actually block reading on the command channel for a notification from the server that the command is finished. Such a notification often carries extra information concerning the completion of the pending action (e.g. number of bytes transfered).

Note that this will return true immediately if no command or action is pending

It should be also noted that most methods issuing commands to the ftp server will call this method if a previous command is pending.

Example of use:

 InputStream in = cl.getFileStream("file");
 ...
 cl.completePending();
 long size = cl.getLastTransferSize();
 
On the other hand, it's not necessary in a case like:
 InputStream in = cl.getFileStream("file");
 // read content
 ...
 cl.logout();
 

Since logout() will call completePending() if necessary.

Returns:
true if the completion was successful or if no action was pending.
Throws:
IOException

reInit

public void reInit()
            throws IOException
Reinitializes the USER parameters on the FTP server

Throws:
FtpProtocolException - if the command fails
IOException

setType

public FtpClient setType(FtpClient.TransferType type)
                  throws IOException
Changes the transfer type (binary, ascii, ebcdic) and issue the proper command (e.g. TYPE A) to the server.

Parameters:
type - the TransferType to use.
Returns:
This FtpClient
Throws:
IOException - if an error occurs during transmission.

setBinaryType

public FtpClient setBinaryType()
                        throws IOException
Changes the current transfer type to binary. This is a convenience method that is equivalent to setType(TransferType.BINARY)

Returns:
This FtpClient
Throws:
IOException - if an error occurs during the transmission.
See Also:
setType(TransferType)

setAsciiType

public FtpClient setAsciiType()
                       throws IOException
Changes the current transfer type to ascii. This is a convenience method that is equivalent to setType(TransferType.ASCII)

Returns:
This FtpClient
Throws:
IOException - if an error occurs during the transmission.
See Also:
setType(TransferType)

list

public InputStream list(String path)
                 throws IOException
Issues a LIST command to the server to get the current directory listing, and returns the InputStream from the data connection. completePending() has to be called once the application is finished writing to the stream.

Parameters:
path - the pathname of the directory to list, or null for the current working directory.
Returns:
the InputStream from the resulting data connection
Throws:
IOException - if an error occurs during the transmission.
See Also:
changeDirectory(String), listFiles(String)

nameList

public InputStream nameList(String path)
                     throws IOException
Issues a NLST path command to server to get the specified directory content. It differs from list(String) method by the fact that it will only list the file names which would make the parsing of the somewhat easier. completePending() has to be called once the application is finished writing to the stream.

Parameters:
path - a String containing the pathname of the directory to list or null for the current working directory.
Returns:
the InputStream from the resulting data connection
Throws:
IOException - if an error occurs during the transmission.

getSize

public long getSize(String path)
             throws IOException
Issues the SIZE [path] command to the server to get the size of a specific file on the server. Note that this command may not be supported by the server. In which case -1 will be returned.

Parameters:
path - a String containing the pathname of the file.
Returns:
a long containing the size of the file or -1 if the server returned an error, which can be checked with getLastReplyCode().
Throws:
IOException - if an error occurs during the transmission.

getLastModified

public Date getLastModified(String path)
                     throws IOException
Issues the MDTM [path] command to the server to get the modification time of a specific file on the server. Note that this command may not be supported by the server, in which case null will be returned.

Parameters:
path - a String containing the pathname of the file.
Returns:
a Date representing the last modification time or null if the server returned an error, which can be checked with getLastReplyCode().
Throws:
IOException - if an error occurs during the transmission.

setFileParser

public void setFileParser(FtpFileParser p)
Sets the parser used to handle the directory output to the specified one. By default the parser is set to one that can handle most FTP servers output (Unix base mostly). However it may be necessary for and application to provide its own parser due to some uncommon output format.

Parameters:
p - The FtpFileParser to use.
See Also:
listFiles(String)

listFiles

public Iterator<FtpFile> listFiles(String path)
                            throws IOException
Issues a MLSD command to the server to get the specified directory listing and applies the current parser to create an Iterator of java.net.ftp.FtpFile. Note that the Iterator returned is also a Closeable. If the server doesn't support the MLSD command, the LIST command is used instead. completePending() has to be called once the application is finished iterating through the files.

Parameters:
path - the pathname of the directory to list or null for the current working directoty.
Returns:
a Iterator of files or null if the command failed.
Throws:
IOException - if an error occured during the transmission
See Also:
setFileParser(FtpFileParser), changeDirectory(String)

useGSSAPI

public boolean useGSSAPI()
                  throws IOException
Attempts to use Kerberos GSSAPI as an authentication mechanism with the ftp server. This will issue an AUTH GSSAPI command, and if it is accepted by the server, will followup with ADAT command to exchange the various tokens until authentification is successful. This conforms to Appendix I of RFC 2228.

Returns:
true if authentication was successful.
Throws:
IOException - if an error occurs during the transmission.

getWelcomeMsg

public String getWelcomeMsg()
Returns the Welcome string the server sent during initial connection.

Returns:
a String containing the message the server returned during connection or null.

getLastReplyCode

public FtpReplyCode getLastReplyCode()
Returns the last reply code sent by the server.

Returns:
the lastReplyCode

getLastResponseString

public String getLastResponseString()
Returns the last response string sent by the server.

Returns:
the message string, which can be quite long, last returned by the server.

getLastTransferSize

public long getLastTransferSize()
Returns, when available, the size of the latest started transfer. This is retreived by parsing the response string received as an initial response to a RETR or similar request.

Returns:
the size of the latest transfer or -1 if either there was no transfer or the information was unavailable.

getLastFileName

public String getLastFileName()
Returns, when available, the remote name of the last transfered file. This is mainly useful for "put" operation when the unique flag was set since it allows to recover the unique file name created on the server which may be different from the one submitted with the command.

Returns:
the name the latest transfered file remote name, or null if that information is unavailable.

useTLS

public boolean useTLS()
               throws IOException
Attempts to switch to a secure, encrypted connection. This is done by sending the "AUTH TLS" command.

See RFC 4217

If successful this will establish a secure command channel with the server, it will also make it so that all other transfers (e.g. a RETR command) will be done over an encrypted channel as well unless a reInit() command or a clearTLS() command is issued.

Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during the transmission.
See Also:
clearTLS()

clearTLS

public boolean clearTLS()
                 throws IOException
Sends a CCC command followed by a PROT C command to the server terminating an encrypted session and reverting back to a non crypted transmission.

Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during transmission.

allocate

public boolean allocate(long size)
                 throws IOException
Sends the "Allocate" (ALLO) command to the server telling it to pre-allocate the specified number of bytes for the next transfer.

Parameters:
size - The number of bytes to allocate.
Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during the transmission.

structureMount

public boolean structureMount(String struct)
                       throws IOException
Sends the "Structure Mount" (SMNT) command to the server. This let the user mount a different file system data structure without altering his login or accounting information.

Parameters:
struct - a String containing the name of the structure to mount.
Returns:
true if the operation was successful.
Throws:
IOException - if an error occured during the transmission.

getSystem

public String getSystem()
                 throws IOException
Sends a SYST (System) command to the server and returns the String sent back by the server describing the operating system at the server.

Returns:
a String describing the OS, or null if the operation was not successful.
Throws:
IOException - if an error occured during the transmission.

getHelp

public String getHelp(String cmd)
               throws IOException
Sends the HELP command to the server, with an optional command, like SITE, and returns the text sent back by the server.

Parameters:
cmd - the command for which the help is requested or null for the general help
Returns:
a String containing the text sent back by the server, or null if the command failed.
Throws:
IOException - if an error occured during transmission

siteCmd

public boolean siteCmd(String cmd)
                throws IOException
Sends the SITE command to the server. This is used by the server to provide services specific to his system that are essential to file transfer.

Parameters:
cmd - the command to be sent.
Returns:
true if the command was successful.
Throws:
IOException - if an error occured during transmission

Java™ Platform
Standard Ed. 7

DRAFT internal-b00

Submit a bug or feature

Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.