Methods Summary |
---|
private void | __initDefaults()
__dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE;
__passiveHost = null;
__passivePort = -1;
__fileType = FTP.ASCII_FILE_TYPE;
__fileStructure = FTP.FILE_STRUCTURE;
__fileFormat = FTP.NON_PRINT_TEXT_FORMAT;
__fileTransferMode = FTP.STREAM_TRANSFER_MODE;
__restartOffset = 0;
__systemName = null;
__entryParser = null;
__bufferSize = Util.DEFAULT_COPY_BUFFER_SIZE;
|
private void | __parsePassiveModeReply(java.lang.String reply)
int i, index, lastIndex;
String octet1, octet2;
StringBuffer host;
reply = reply.substring(reply.indexOf('(") + 1,
reply.indexOf(')")).trim();
host = new StringBuffer(24);
lastIndex = 0;
index = reply.indexOf(',");
host.append(reply.substring(lastIndex, index));
for (i = 0; i < 3; i++)
{
host.append('.");
lastIndex = index + 1;
index = reply.indexOf(',", lastIndex);
host.append(reply.substring(lastIndex, index));
}
lastIndex = index + 1;
index = reply.indexOf(',", lastIndex);
octet1 = reply.substring(lastIndex, index);
octet2 = reply.substring(index + 1);
// index and lastIndex now used as temporaries
try
{
index = Integer.parseInt(octet1);
lastIndex = Integer.parseInt(octet2);
}
catch (NumberFormatException e)
{
throw new MalformedServerReplyException(
"Could not parse passive host information.\nServer Reply: " + reply);
}
index <<= 8;
index |= lastIndex;
__passiveHost = host.toString();
__passivePort = index;
|
private java.lang.String | __parsePathname(java.lang.String reply)
int begin, end;
begin = reply.indexOf('"") + 1;
end = reply.indexOf('"", begin);
return reply.substring(begin, end);
|
private boolean | __storeFile(int command, java.lang.String remote, java.io.InputStream local)
OutputStream output;
Socket socket;
if ((socket = _openDataConnection_(command, remote)) == null)
return false;
output = new BufferedOutputStream(socket.getOutputStream(),
getBufferSize()
);
if (__fileType == ASCII_FILE_TYPE)
output = new ToNetASCIIOutputStream(output);
// Treat everything else as binary for now
try
{
Util.copyStream(local, output, getBufferSize(),
CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,
false);
}
catch (IOException e)
{
try
{
socket.close();
}
catch (IOException f)
{}
throw e;
}
output.close();
socket.close();
return completePendingCommand();
|
private java.io.OutputStream | __storeFileStream(int command, java.lang.String remote)
OutputStream output;
Socket socket;
if ((socket = _openDataConnection_(command, remote)) == null)
return null;
output = socket.getOutputStream();
if (__fileType == ASCII_FILE_TYPE) {
// We buffer ascii transfers because the buffering has to
// be interposed between ToNetASCIIOutputSream and the underlying
// socket output stream. We don't buffer binary transfers
// because we don't want to impose a buffering policy on the
// programmer if possible. Programmers can decide on their
// own if they want to wrap the SocketOutputStream we return
// for file types other than ASCII.
output = new BufferedOutputStream(output,
getBufferSize());
output = new ToNetASCIIOutputStream(output);
}
return new org.apache.commons.net.io.SocketOutputStream(socket, output);
|
protected void | _connectAction_()
super._connectAction_();
__initDefaults();
|
protected java.net.Socket | _openDataConnection_(int command, java.lang.String arg)Establishes a data connection with the FTP server, returning
a Socket for the connection if successful. If a restart
offset has been set with {@link #setRestartOffset(long)},
a REST command is issued to the server with the offset as
an argument before establishing the data connection. Active
mode connections also cause a local PORT command to be issued.
Socket socket;
if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE &&
__dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE)
return null;
if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE)
{
ServerSocket server;
server = _socketFactory_.createServerSocket(0, 1, getLocalAddress());
if (!FTPReply.isPositiveCompletion(port(getLocalAddress(),
server.getLocalPort())))
{
server.close();
return null;
}
if ((__restartOffset > 0) && !restart(__restartOffset))
{
server.close();
return null;
}
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
{
server.close();
return null;
}
// For now, let's just use the data timeout value for waiting for
// the data connection. It may be desirable to let this be a
// separately configurable value. In any case, we really want
// to allow preventing the accept from blocking indefinitely.
if (__dataTimeout >= 0)
server.setSoTimeout(__dataTimeout);
socket = server.accept();
server.close();
}
else
{ // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE
if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
return null;
__parsePassiveModeReply((String)_replyLines.elementAt(0));
socket = _socketFactory_.createSocket(__passiveHost, __passivePort);
if ((__restartOffset > 0) && !restart(__restartOffset))
{
socket.close();
return null;
}
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
{
socket.close();
return null;
}
}
if (__remoteVerificationEnabled && !verifyRemote(socket))
{
InetAddress host1, host2;
host1 = socket.getInetAddress();
host2 = getRemoteAddress();
socket.close();
throw new IOException(
"Host attempting data connection " + host1.getHostAddress() +
" is not same as server " + host2.getHostAddress());
}
if (__dataTimeout >= 0)
socket.setSoTimeout(__dataTimeout);
return socket;
|
public boolean | abort()Abort a transfer in progress.
return FTPReply.isPositiveCompletion(abor());
|
public boolean | allocate(int bytes)Reserve a number of bytes on the server for the next file transfer.
return FTPReply.isPositiveCompletion(allo(bytes));
|
public boolean | allocate(int bytes, int recordSize)Reserve space on the server for the next file transfer.
return FTPReply.isPositiveCompletion(allo(bytes, recordSize));
|
public boolean | appendFile(java.lang.String remote, java.io.InputStream local)Appends to a file on the server with the given name, taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
return __storeFile(FTPCommand.APPE, remote, local);
|
public java.io.OutputStream | appendFileStream(java.lang.String remote)Returns an OutputStream through which data can be written to append
to a file on the server with the given name. If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
{@link #completePendingCommand completePendingCommand } and
check its return value to verify success.
return __storeFileStream(FTPCommand.APPE, remote);
|
public boolean | changeToParentDirectory()Change to the parent directory of the current working directory.
return FTPReply.isPositiveCompletion(cdup());
|
public boolean | changeWorkingDirectory(java.lang.String pathname)Change the current working directory of the FTP session.
return FTPReply.isPositiveCompletion(cwd(pathname));
|
public boolean | completePendingCommand()There are a few FTPClient methods that do not complete the
entire sequence of FTP commands to complete a transaction. These
commands require some action by the programmer after the reception
of a positive intermediate command. After the programmer's code
completes its actions, it must call this method to receive
the completion reply from the server and verify the success of the
entire transaction.
For example,
InputStream input;
OutputStream output;
input = new FileInputStream("foobaz.txt");
output = ftp.storeFileStream("foobar.txt")
if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {
input.close();
output.close();
ftp.logout();
ftp.disconnect();
System.err.println("File transfer failed.");
System.exit(1);
}
Util.copyStream(input, output);
input.close();
output.close();
// Must call completePendingCommand() to finish command.
if(!ftp.completePendingCommand()) {
ftp.logout();
ftp.disconnect();
System.err.println("File transfer failed.");
System.exit(1);
}
return FTPReply.isPositiveCompletion(getReply());
|
public void | configure(FTPClientConfig config)Implementation of the {@link Configurable Configurable} interface.
In the case of this class, configuring merely makes the config object available for the
factory methods that construct parsers.
this.__configuration = config;
|
public FTPFileList | createFileList(FTPFileEntryParser parser)Using a programmer specified FTPFileEntryParser ,
initialize an object containing a raw file information for the
current working directory. This information is obtained through
the LIST command. This object is then capable of being iterated to
return a sequence of FTPFile objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
return createFileList(null, parser);
|
public FTPFileList | createFileList(java.lang.String pathname, FTPFileEntryParser parser)Using a programmer specified FTPFileEntryParser ,
initialize an object containing a raw file information for a directory
or information for a single file. This information is obtained through
the LIST command. This object is then capable of being iterated to
return a sequence of FTPFile objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
Socket socket;
if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null)
{
return null;
}
FTPFileList list = FTPFileList.create(socket.getInputStream(), parser);
socket.close();
completePendingCommand();
return list;
|
public boolean | deleteFile(java.lang.String pathname)Deletes a file on the FTP server.
return FTPReply.isPositiveCompletion(dele(pathname));
|
public void | disconnect()Closes the connection to the FTP server and restores
connection parameters to the default values.
super.disconnect();
__initDefaults();
|
public void | enterLocalActiveMode()Set the current data connection mode to
ACTIVE_LOCAL_DATA_CONNECTION_MODE . No communication
with the FTP server is conducted, but this causes all future data
transfers to require the FTP server to connect to the client's
data port. Additionally, to accommodate differences between socket
implementations on different platforms, this method causes the
client to issue a PORT command before every data transfer.
__dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE;
__passiveHost = null;
__passivePort = -1;
|
public void | enterLocalPassiveMode()Set the current data connection mode to
PASSIVE_LOCAL_DATA_CONNECTION_MODE . Use this
method only for data transfers between the client and server.
This method causes a PASV command to be issued to the server
before the opening of every data connection, telling the server to
open a data port to which the client will connect to conduct
data transfers. The FTPClient will stay in
PASSIVE_LOCAL_DATA_CONNECTION_MODE until the
mode is changed by calling some other method such as
{@link #enterLocalActiveMode enterLocalActiveMode() }
__dataConnectionMode = PASSIVE_LOCAL_DATA_CONNECTION_MODE;
// These will be set when just before a data connection is opened
// in _openDataConnection_()
__passiveHost = null;
__passivePort = -1;
|
public boolean | enterRemoteActiveMode(java.net.InetAddress host, int port)Set the current data connection mode to
ACTIVE_REMOTE_DATA_CONNECTION . Use this method only
for server to server data transfers. This method issues a PORT
command to the server, indicating the other server and port to which
it should connect for data transfers. You must call this method
before EVERY server to server transfer attempt. The FTPClient will
NOT automatically continue to issue PORT commands. You also
must remember to call
{@link #enterLocalActiveMode enterLocalActiveMode() } if you
wish to return to the normal data connection mode.
if (FTPReply.isPositiveCompletion(port(host, port)))
{
__dataConnectionMode = ACTIVE_REMOTE_DATA_CONNECTION_MODE;
__passiveHost = null;
__passivePort = -1;
return true;
}
return false;
|
public boolean | enterRemotePassiveMode()Set the current data connection mode to
PASSIVE_REMOTE_DATA_CONNECTION_MODE . Use this
method only for server to server data transfers.
This method issues a PASV command to the server, telling it to
open a data port to which the active server will connect to conduct
data transfers. You must call this method
before EVERY server to server transfer attempt. The FTPClient will
NOT automatically continue to issue PASV commands. You also
must remember to call
{@link #enterLocalActiveMode enterLocalActiveMode() } if you
wish to return to the normal data connection mode.
if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
return false;
__dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE;
__parsePassiveModeReply((String)_replyLines.elementAt(0));
return true;
|
public int | getBufferSize()Retrieve the current internal buffer size.
return __bufferSize;
|
public int | getDataConnectionMode()Returns the current data connection mode (one of the
_DATA_CONNECTION_MODE constants.
return __dataConnectionMode;
|
public java.lang.String | getPassiveHost()Returns the hostname or IP address (in the form of a string) returned
by the server when entering passive mode. If not in passive mode,
returns null. This method only returns a valid value AFTER a
data connection has been opened after a call to
{@link #enterLocalPassiveMode enterLocalPassiveMode()}.
This is because FTPClient sends a PASV command to the server only
just before opening a data connection, and not when you call
{@link #enterLocalPassiveMode enterLocalPassiveMode()}.
return __passiveHost;
|
public int | getPassivePort()If in passive mode, returns the data port of the passive host.
This method only returns a valid value AFTER a
data connection has been opened after a call to
{@link #enterLocalPassiveMode enterLocalPassiveMode()}.
This is because FTPClient sends a PASV command to the server only
just before opening a data connection, and not when you call
{@link #enterLocalPassiveMode enterLocalPassiveMode()}.
return __passivePort;
|
public long | getRestartOffset()Fetches the restart offset.
return __restartOffset;
|
public java.lang.String | getStatus()Issue the FTP STAT command to the server.
if (FTPReply.isPositiveCompletion(stat()))
return getReplyString();
return null;
|
public java.lang.String | getStatus(java.lang.String pathname)Issue the FTP STAT command to the server for a given pathname. This
should produce a listing of the file or directory.
if (FTPReply.isPositiveCompletion(stat(pathname)))
return getReplyString();
return null;
|
public java.lang.String | getSystemName()Fetches the system type name from the server and returns the string.
This value is cached for the duration of the connection after the
first call to this method. In other words, only the first time
that you invoke this method will it issue a SYST command to the
FTP server. FTPClient will remember the value and return the
cached value until a call to disconnect.
//if (syst() == FTPReply.NAME_SYSTEM_TYPE)
// Technically, we should expect a NAME_SYSTEM_TYPE response, but
// in practice FTP servers deviate, so we soften the condition to
// a positive completion.
if (__systemName == null && FTPReply.isPositiveCompletion(syst()))
__systemName = ((String)_replyLines.elementAt(0)).substring(4);
return __systemName;
|
public FTPListParseEngine | initiateListParsing()Using the default autodetect mechanism, initialize an FTPListParseEngine
object containing a raw file information for the current working
directory on the server
This information is obtained through the LIST command. This object
is then capable of being iterated to return a sequence of FTPFile
objects with information filled in by the
FTPFileEntryParser used.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
return initiateListParsing((String) null);
|
public FTPListParseEngine | initiateListParsing(java.lang.String pathname)Using the default autodetect mechanism, initialize an FTPListParseEngine
object containing a raw file information for the supplied directory.
This information is obtained through the LIST command. This object
is then capable of being iterated to return a sequence of FTPFile
objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
FTPClient f=FTPClient();
f.connect(server);
f.login(username, password);
FTPListParseEngine engine = f.initiateListParsing(directory);
while (engine.hasNext()) {
FTPFile[] files = engine.getNext(25); // "page size" you want
//do whatever you want with these files, display them, etc.
//expensive FTPFile objects not created until needed.
}
String key = null;
return initiateListParsing(key, pathname);
|
public FTPListParseEngine | initiateListParsing(java.lang.String parserKey, java.lang.String pathname)Using the supplied parser key, initialize an FTPListParseEngine
object containing a raw file information for the supplied directory.
This information is obtained through the LIST command. This object
is then capable of being iterated to return a sequence of FTPFile
objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
// We cache the value to avoid creation of a new object every
// time a file listing is generated.
if(__entryParser == null) {
if (null != parserKey) {
// if a parser key was supplied in the parameters,
// use that to create the paraser
__entryParser =
__parserFactory.createFileEntryParser(parserKey);
} else {
// if no parserKey was supplied, check for a configuration
// in the params, and if non-null, use that.
if (null != __configuration) {
__entryParser =
__parserFactory.createFileEntryParser(__configuration);
} else {
// if a parserKey hasn't been supplied, and a configuration
// hasn't been supplied, then autodetect by calling
// the SYST command and use that to choose the parser.
__entryParser =
__parserFactory.createFileEntryParser(getSystemName());
}
}
}
return initiateListParsing(__entryParser, pathname);
|
private FTPListParseEngine | initiateListParsing(FTPFileEntryParser parser, java.lang.String pathname)private method through which all listFiles() and
initiateListParsing methods pass once a parser is determined.
Socket socket;
FTPListParseEngine engine = new FTPListParseEngine(parser);
if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null)
{
return engine;
}
engine.readServerList(socket.getInputStream(), getControlEncoding());
socket.close();
completePendingCommand();
return engine;
|
public boolean | isRemoteVerificationEnabled()Return whether or not verification of the remote host participating
in data connections is enabled. The default behavior is for
verification to be enabled.
return __remoteVerificationEnabled;
|
public FTPFile[] | listFiles(java.lang.String parserKey, java.lang.String pathname)Using the supplied parserKey , obtain a list
of file information for the current working directory or for just a
single file.
If key is null, this object will try to autodetect
the system-type/parser-type by calling the SYST command.
Under the DefaultFTPFileEntryParserFactory, which is used unless a
different factory has been specified, the key
can be either a recognized System type for which a parser has been
defined, or the fully qualified class name of a class that implements
org.apache.commons.net.ftp.FTPFileEntryParser.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
FTPListParseEngine engine =
initiateListParsing(parserKey, pathname);
return engine.getFiles();
|
public FTPFile[] | listFiles(java.lang.String pathname)Using the default system autodetect mechanism, obtain a
list of file information for the current working directory
or for just a single file.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
String key = null;
FTPListParseEngine engine =
initiateListParsing(key, pathname);
return engine.getFiles();
|
public FTPFile[] | listFiles()Using the default system autodetect mechanism, obtain a
list of file information for the current working directory.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
return listFiles((String) null);
|
public FTPFile[] | listFiles(FTPFileListParser parser, java.lang.String pathname)Using a programmer specified FTPFileListParser , obtain a
list of file information for a directory or information for
just a single file. This information is obtained through the LIST
command. The contents of the returned array is determined by the
FTPFileListParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
Socket socket;
FTPFile[] results;
if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null)
return new FTPFile[0];
results = parser.parseFileList(socket.getInputStream(), getControlEncoding());
socket.close();
completePendingCommand();
return results;
|
public FTPFile[] | listFiles(FTPFileListParser parser)Using a programmer specified FTPFileListParser ,
obtain a list of file information for the current working directory.
This information is obtained through the LIST command.
The contents of the array returned is determined by the
FTPFileListParser used.
return listFiles(parser, null);
|
public java.lang.String | listHelp()Fetches the system help information from the server and returns the
full string.
if (FTPReply.isPositiveCompletion(help()))
return getReplyString();
return null;
|
public java.lang.String | listHelp(java.lang.String command)Fetches the help information for a given command from the server and
returns the full string.
if (FTPReply.isPositiveCompletion(help(command)))
return getReplyString();
return null;
|
public java.lang.String[] | listNames(java.lang.String pathname)Obtain a list of filenames in a directory (or just the name of a given
file, which is not particularly useful). This information is obtained
through the NLST command. If the given pathname is a directory and
contains no files, a zero length array is returned only
if the FTP server returned a positive completion code, otherwise
null is returned (the FTP server returned a 550 error No files found.).
If the directory is not empty, an array of filenames in the directory is
returned. If the pathname corresponds
to a file, only that file will be listed. The server may or may not
expand glob expressions.
String line;
Socket socket;
BufferedReader reader;
Vector results;
if ((socket = _openDataConnection_(FTPCommand.NLST, pathname)) == null)
return null;
reader =
new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
results = new Vector();
while ((line = reader.readLine()) != null)
results.addElement(line);
reader.close();
socket.close();
if (completePendingCommand())
{
String[] result;
result = new String[results.size()];
results.copyInto(result);
return result;
}
return null;
|
public java.lang.String[] | listNames()Obtain a list of filenames in the current working directory
This information is obtained through the NLST command. If the current
directory contains no files, a zero length array is returned only
if the FTP server returned a positive completion code, otherwise,
null is returned (the FTP server returned a 550 error No files found.).
If the directory is not empty, an array of filenames in the directory is
returned.
return listNames(null);
|
public boolean | login(java.lang.String username, java.lang.String password)Login to the FTP server using the provided username and password.
user(username);
if (FTPReply.isPositiveCompletion(_replyCode))
return true;
// If we get here, we either have an error code, or an intermmediate
// reply requesting password.
if (!FTPReply.isPositiveIntermediate(_replyCode))
return false;
return FTPReply.isPositiveCompletion(pass(password));
|
public boolean | login(java.lang.String username, java.lang.String password, java.lang.String account)Login to the FTP server using the provided username, password,
and account. If no account is required by the server, only
the username and password, the account information is not used.
user(username);
if (FTPReply.isPositiveCompletion(_replyCode))
return true;
// If we get here, we either have an error code, or an intermmediate
// reply requesting password.
if (!FTPReply.isPositiveIntermediate(_replyCode))
return false;
pass(password);
if (FTPReply.isPositiveCompletion(_replyCode))
return true;
if (!FTPReply.isPositiveIntermediate(_replyCode))
return false;
return FTPReply.isPositiveCompletion(acct(account));
|
public boolean | logout()Logout of the FTP server by sending the QUIT command.
return FTPReply.isPositiveCompletion(quit());
|
public boolean | makeDirectory(java.lang.String pathname)Creates a new subdirectory on the FTP server in the current directory
(if a relative pathname is given) or where specified (if an absolute
pathname is given).
return FTPReply.isPositiveCompletion(mkd(pathname));
|
public java.lang.String | printWorkingDirectory()Returns the pathname of the current working directory.
if (pwd() != FTPReply.PATHNAME_CREATED)
return null;
return __parsePathname((String)_replyLines.elementAt(0));
|
boolean | reinitialize()Reinitialize the FTP session. Not all FTP servers support this
command, which issues the FTP REIN command.
rein();
if (FTPReply.isPositiveCompletion(_replyCode) ||
(FTPReply.isPositivePreliminary(_replyCode) &&
FTPReply.isPositiveCompletion(getReply())))
{
__initDefaults();
return true;
}
return false;
|
public boolean | remoteAppend(java.lang.String filename)Initiate a server to server file transfer. This method tells the
server to which the client is connected to append to a given file on
the other server. The other server must have had a
remoteRetrieve issued to it by another FTPClient.
if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||
__dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)
return FTPReply.isPositivePreliminary(stor(filename));
return false;
|
public boolean | remoteRetrieve(java.lang.String filename)Initiate a server to server file transfer. This method tells the
server to which the client is connected to retrieve a given file from
the other server.
if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||
__dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)
return FTPReply.isPositivePreliminary(retr(filename));
return false;
|
public boolean | remoteStore(java.lang.String filename)Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using the given filename. The other server must
have had a remoteRetrieve issued to it by another
FTPClient.
if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||
__dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)
return FTPReply.isPositivePreliminary(stor(filename));
return false;
|
public boolean | remoteStoreUnique(java.lang.String filename)Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using a unique filename based on the given filename.
The other server must have had a remoteRetrieve issued
to it by another FTPClient.
if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||
__dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)
return FTPReply.isPositivePreliminary(stou(filename));
return false;
|
public boolean | remoteStoreUnique()Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using a unique filename.
The other server must have had a remoteRetrieve issued
to it by another FTPClient. Many FTP servers require that a base
filename be given from which the unique filename can be derived. For
those servers use the other version of remoteStoreUnique
if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||
__dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE)
return FTPReply.isPositivePreliminary(stou());
return false;
|
public boolean | removeDirectory(java.lang.String pathname)Removes a directory on the FTP server (if empty).
return FTPReply.isPositiveCompletion(rmd(pathname));
|
public boolean | rename(java.lang.String from, java.lang.String to)Renames a remote file.
if (!FTPReply.isPositiveIntermediate(rnfr(from)))
return false;
return FTPReply.isPositiveCompletion(rnto(to));
|
private boolean | restart(long offset)Restart a STREAM_TRANSFER_MODE file transfer starting
from the given offset. This will only work on FTP servers supporting
the REST comand for the stream transfer mode. However, most FTP
servers support this. Any subsequent file transfer will start
reading or writing the remote file from the indicated offset.
__restartOffset = 0;
return FTPReply.isPositiveIntermediate(rest(Long.toString(offset)));
|
public boolean | retrieveFile(java.lang.String remote, java.io.OutputStream local)Retrieves a named file from the server and writes it to the given
OutputStream. This method does NOT close the given OutputStream.
If the current file type is ASCII, line separators in the file are
converted to the local representation.
InputStream input;
Socket socket;
if ((socket = _openDataConnection_(FTPCommand.RETR, remote)) == null)
return false;
input = new BufferedInputStream(socket.getInputStream(),
getBufferSize());
if (__fileType == ASCII_FILE_TYPE)
input = new FromNetASCIIInputStream(input);
// Treat everything else as binary for now
try
{
Util.copyStream(input, local, getBufferSize(),
CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,
false);
}
catch (IOException e)
{
try
{
socket.close();
}
catch (IOException f)
{}
throw e;
}
socket.close();
return completePendingCommand();
|
public java.io.InputStream | retrieveFileStream(java.lang.String remote)Returns an InputStream from which a named file from the server
can be read. If the current file type is ASCII, the returned
InputStream will convert line separators in the file to
the local representation. You must close the InputStream when you
finish reading from it. The InputStream itself will take care of
closing the parent data connection socket upon being closed. To
finalize the file transfer you must call
{@link #completePendingCommand completePendingCommand } and
check its return value to verify success.
InputStream input;
Socket socket;
if ((socket = _openDataConnection_(FTPCommand.RETR, remote)) == null)
return null;
input = socket.getInputStream();
if (__fileType == ASCII_FILE_TYPE) {
// We buffer ascii transfers because the buffering has to
// be interposed between FromNetASCIIOutputSream and the underlying
// socket input stream. We don't buffer binary transfers
// because we don't want to impose a buffering policy on the
// programmer if possible. Programmers can decide on their
// own if they want to wrap the SocketInputStream we return
// for file types other than ASCII.
input = new BufferedInputStream(input,
getBufferSize());
input = new FromNetASCIIInputStream(input);
}
return new org.apache.commons.net.io.SocketInputStream(socket, input);
|
public boolean | sendNoOp()Sends a NOOP command to the FTP server. This is useful for preventing
server timeouts.
return FTPReply.isPositiveCompletion(noop());
|
public boolean | sendSiteCommand(java.lang.String arguments)Send a site specific command.
return FTPReply.isPositiveCompletion(site(arguments));
|
public void | setBufferSize(int bufSize)Set the internal buffer size.
__bufferSize = bufSize;
|
public void | setDataTimeout(int timeout)Sets the timeout in milliseconds to use when reading from the
data connection. This timeout will be set immediately after
opening the data connection.
__dataTimeout = timeout;
|
public boolean | setFileStructure(int structure)Sets the file structure. The default structure is
FTP.FILE_STRUCTURE if this method is never called.
if (FTPReply.isPositiveCompletion(stru(structure)))
{
__fileStructure = structure;
return true;
}
return false;
|
public boolean | setFileTransferMode(int mode)Sets the transfer mode. The default transfer mode
FTP.STREAM_TRANSFER_MODE if this method is never called.
if (FTPReply.isPositiveCompletion(mode(mode)))
{
__fileTransferMode = mode;
return true;
}
return false;
|
public boolean | setFileType(int fileType)Sets the file type to be transferred. This should be one of
FTP.ASCII_FILE_TYPE , FTP.IMAGE_FILE_TYPE ,
etc. The file type only needs to be set when you want to change the
type. After changing it, the new type stays in effect until you change
it again. The default file type is FTP.ASCII_FILE_TYPE
if this method is never called.
if (FTPReply.isPositiveCompletion(type(fileType)))
{
__fileType = fileType;
__fileFormat = FTP.NON_PRINT_TEXT_FORMAT;
return true;
}
return false;
|
public boolean | setFileType(int fileType, int formatOrByteSize)Sets the file type to be transferred and the format. The type should be
one of FTP.ASCII_FILE_TYPE ,
FTP.IMAGE_FILE_TYPE , etc. The file type only needs to
be set when you want to change the type. After changing it, the new
type stays in effect until you change it again. The default file type
is FTP.ASCII_FILE_TYPE if this method is never called.
The format should be one of the FTP class TEXT_FORMAT
constants, or if the type is FTP.LOCAL_FILE_TYPE , the
format should be the byte size for that type. The default format
is FTP.NON_PRINT_TEXT_FORMAT if this method is never
called.
if (FTPReply.isPositiveCompletion(type(fileType, formatOrByteSize)))
{
__fileType = fileType;
__fileFormat = formatOrByteSize;
return true;
}
return false;
|
public void | setParserFactory(org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory parserFactory)set the factory used for parser creation to the supplied factory object.
__parserFactory = parserFactory;
|
public void | setRemoteVerificationEnabled(boolean enable)Enable or disable verification that the remote host taking part
of a data connection is the same as the host to which the control
connection is attached. The default is for verification to be
enabled. You may set this value at any time, whether the
FTPClient is currently connected or not.
__remoteVerificationEnabled = enable;
|
public void | setRestartOffset(long offset)Sets the restart offset. The restart command is sent to the server
only before sending the file transfer command. When this is done,
the restart marker is reset to zero.
if (offset >= 0)
__restartOffset = offset;
|
public boolean | storeFile(java.lang.String remote, java.io.InputStream local)Stores a file on the server using the given name and taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
return __storeFile(FTPCommand.STOR, remote, local);
|
public java.io.OutputStream | storeFileStream(java.lang.String remote)Returns an OutputStream through which data can be written to store
a file on the server using the given name. If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
{@link #completePendingCommand completePendingCommand } and
check its return value to verify success.
return __storeFileStream(FTPCommand.STOR, remote);
|
public boolean | storeUniqueFile(java.lang.String remote, java.io.InputStream local)Stores a file on the server using a unique name derived from the
given name and taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
return __storeFile(FTPCommand.STOU, remote, local);
|
public boolean | storeUniqueFile(java.io.InputStream local)Stores a file on the server using a unique name assigned by the
server and taking input from the given InputStream. This method does
NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
return __storeFile(FTPCommand.STOU, null, local);
|
public java.io.OutputStream | storeUniqueFileStream(java.lang.String remote)Returns an OutputStream through which data can be written to store
a file on the server using a unique name derived from the given name.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
{@link #completePendingCommand completePendingCommand } and
check its return value to verify success.
return __storeFileStream(FTPCommand.STOU, remote);
|
public java.io.OutputStream | storeUniqueFileStream()Returns an OutputStream through which data can be written to store
a file on the server using a unique name assigned by the server.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
{@link #completePendingCommand completePendingCommand } and
check its return value to verify success.
return __storeFileStream(FTPCommand.STOU, null);
|
public boolean | structureMount(java.lang.String pathname)Issue the FTP SMNT command.
return FTPReply.isPositiveCompletion(smnt(pathname));
|