mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8187443: Forest Consolidation: Move files to unified layout
Reviewed-by: darcy, ihse
This commit is contained in:
parent
270fe13182
commit
3789983e89
56923 changed files with 3 additions and 15727 deletions
943
src/java.base/share/classes/sun/net/ftp/FtpClient.java
Normal file
943
src/java.base/share/classes/sun/net/ftp/FtpClient.java
Normal file
|
@ -0,0 +1,943 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp;
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A class that implements the FTP protocol according to
|
||||
* RFCs <A href="http://www.ietf.org/rfc/rfc0959.txt">959</A>,
|
||||
* <A href="http://www.ietf.org/rfc/rfc2228.txt">2228</A>,
|
||||
* <A href="http://www.ietf.org/rfc/rfc2389.txt">2389</A>,
|
||||
* <A href="http://www.ietf.org/rfc/rfc2428.txt">2428</A>,
|
||||
* <A href="http://www.ietf.org/rfc/rfc3659.txt">3659</A>,
|
||||
* <A href="http://www.ietf.org/rfc/rfc4217.txt">4217</A>.
|
||||
* Which includes support for FTP over SSL/TLS (aka ftps).
|
||||
*
|
||||
* {@code FtpClient} provides all the functionalities 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:
|
||||
* <pre>
|
||||
* FtpClient cl = FtpClient.create();
|
||||
* cl.connect("ftp.gnu.org").login("anonymous", "john.doe@mydomain.com".toCharArray())).changeDirectory("pub/gnu");
|
||||
* Iterator<FtpDirEntry> dir = cl.listFiles();
|
||||
* while (dir.hasNext()) {
|
||||
* FtpDirEntry f = dir.next();
|
||||
* System.err.println(f.getName());
|
||||
* }
|
||||
* cl.close();
|
||||
* }
|
||||
* </pre>
|
||||
* <p><b>Error reporting:</b> There are, mostly, two families of errors that
|
||||
* can occur during an FTP session. The first kind are the network related issues
|
||||
* like a connection reset, and they are usually fatal to the session, meaning,
|
||||
* in all likelyhood the connection to the server has been lost and the session
|
||||
* should be restarted from scratch. These errors are reported by throwing an
|
||||
* {@link IOException}. The second kind are the errors reported by the FTP server,
|
||||
* like when trying to download a non-existing file for example. These errors
|
||||
* are usually non fatal to the session, meaning more commands can be sent to the
|
||||
* server. In these cases, a {@link FtpProtocolException} is thrown.</p>
|
||||
* <p>
|
||||
* 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
|
||||
*/
|
||||
public abstract class FtpClient implements java.io.Closeable {
|
||||
|
||||
private static final int FTP_PORT = 21;
|
||||
|
||||
public static enum TransferType {
|
||||
|
||||
ASCII, BINARY, EBCDIC
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the default FTP port number.
|
||||
*
|
||||
* @return the port number.
|
||||
*/
|
||||
public static final int defaultPort() {
|
||||
return FTP_PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of FtpClient. The client is not connected to any
|
||||
* server yet.
|
||||
*
|
||||
*/
|
||||
protected FtpClient() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code FtpClient}. The client is not connected to any
|
||||
* server yet.
|
||||
*
|
||||
* @return the created {@code FtpClient}
|
||||
*/
|
||||
public static FtpClient create() {
|
||||
FtpClientProvider provider = FtpClientProvider.provider();
|
||||
return provider.createFtpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of FtpClient and connects it to the specified
|
||||
* address.
|
||||
*
|
||||
* @param dest the {@code InetSocketAddress} to connect to.
|
||||
* @return The created {@code FtpClient}
|
||||
* @throws IOException if the connection fails
|
||||
* @see #connect(java.net.SocketAddress)
|
||||
*/
|
||||
public static FtpClient create(InetSocketAddress dest) throws FtpProtocolException, IOException {
|
||||
FtpClient client = create();
|
||||
if (dest != null) {
|
||||
client.connect(dest);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code FtpClient} and connects it to the
|
||||
* specified host on the default FTP port.
|
||||
*
|
||||
* @param dest the {@code String} containing the name of the host
|
||||
* to connect to.
|
||||
* @return The created {@code FtpClient}
|
||||
* @throws IOException if the connection fails.
|
||||
* @throws FtpProtocolException if the server rejected the connection
|
||||
*/
|
||||
public static FtpClient create(String dest) throws FtpProtocolException, IOException {
|
||||
return create(new InetSocketAddress(dest, FTP_PORT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables, or disables, the use of the <I>passive</I> mode. 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. If set to {@code false} the mode is said to be
|
||||
* <I>active</I> which means the server will connect back to the client
|
||||
* after a PORT command to establish a data connection.
|
||||
*
|
||||
* <p><b>Note:</b> Since the passive mode might not be supported by all
|
||||
* FTP servers, enabling it means the client will try to use it. If the
|
||||
* server rejects it, then the client will attempt to fall back to using
|
||||
* the <I>active</I> mode by issuing a {@code PORT} command instead.</p>
|
||||
*
|
||||
* @param passive {@code true} to force passive mode.
|
||||
* @return This FtpClient
|
||||
* @see #isPassiveModeEnabled()
|
||||
*/
|
||||
public abstract FtpClient enablePassiveMode(boolean passive);
|
||||
|
||||
/**
|
||||
* Tests whether passive mode is enabled.
|
||||
*
|
||||
* @return {@code true} if the passive mode has been enabled.
|
||||
* @see #enablePassiveMode(boolean)
|
||||
*/
|
||||
public abstract boolean isPassiveModeEnabled();
|
||||
|
||||
/**
|
||||
* Sets the default timeout value to use when connecting to the server,
|
||||
*
|
||||
* @param timeout the timeout value, in milliseconds, to use for the connect
|
||||
* operation. A value of zero or less, means use the default timeout.
|
||||
*
|
||||
* @return This FtpClient
|
||||
*/
|
||||
public abstract FtpClient setConnectTimeout(int timeout);
|
||||
|
||||
/**
|
||||
* Returns the current default connection timeout value.
|
||||
*
|
||||
* @return the value, in milliseconds, of the current connect timeout.
|
||||
* @see #setConnectTimeout(int)
|
||||
*/
|
||||
public abstract int getConnectTimeout();
|
||||
|
||||
/**
|
||||
* Sets the timeout value to use when reading from the server,
|
||||
*
|
||||
* @param timeout the timeout value, in milliseconds, to use for the read
|
||||
* operation. A value of zero or less, means use the default timeout.
|
||||
* @return This FtpClient
|
||||
*/
|
||||
public abstract FtpClient setReadTimeout(int timeout);
|
||||
|
||||
/**
|
||||
* Returns the current read timeout value.
|
||||
*
|
||||
* @return the value, in milliseconds, of the current read timeout.
|
||||
* @see #setReadTimeout(int)
|
||||
*/
|
||||
public abstract int getReadTimeout();
|
||||
|
||||
/**
|
||||
* Set the {@code Proxy} to be used for the next connection.
|
||||
* If the client is already connected, it doesn't affect the current
|
||||
* connection. However it is not recommended to change this during a session.
|
||||
*
|
||||
* @param p the {@code Proxy} to use, or {@code null} for no proxy.
|
||||
* @return This FtpClient
|
||||
*/
|
||||
public abstract FtpClient setProxy(Proxy p);
|
||||
|
||||
/**
|
||||
* Get the proxy of this FtpClient
|
||||
*
|
||||
* @return the {@code Proxy}, this client is using, or {@code null}
|
||||
* if none is used.
|
||||
* @see #setProxy(Proxy)
|
||||
*/
|
||||
public abstract Proxy getProxy();
|
||||
|
||||
/**
|
||||
* Tests whether this client is connected or not to a server.
|
||||
*
|
||||
* @return {@code true} if the client is connected.
|
||||
*/
|
||||
public abstract boolean isConnected();
|
||||
|
||||
/**
|
||||
* Connects the {@code FtpClient} to the specified destination server.
|
||||
*
|
||||
* @param dest the address of the destination server
|
||||
* @return this FtpClient
|
||||
* @throws IOException if connection failed.
|
||||
* @throws SecurityException if there is a SecurityManager installed and it
|
||||
* denied the authorization to connect to the destination.
|
||||
* @throws FtpProtocolException
|
||||
*/
|
||||
public abstract FtpClient connect(SocketAddress dest) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Connects the FtpClient to the specified destination server.
|
||||
*
|
||||
* @param dest the address of the destination server
|
||||
* @param timeout the value, in milliseconds, to use as a connection timeout
|
||||
* @return this FtpClient
|
||||
* @throws IOException if connection failed.
|
||||
* @throws SecurityException if there is a SecurityManager installed and it
|
||||
* denied the authorization to connect to the destination.
|
||||
* @throws FtpProtocolException
|
||||
*/
|
||||
public abstract FtpClient connect(SocketAddress dest, int timeout) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Retrieves the address of the FTP server this client is connected to.
|
||||
*
|
||||
* @return the {@link SocketAddress} of the server, or {@code null} if this
|
||||
* client is not connected yet.
|
||||
*/
|
||||
public abstract SocketAddress getServerAddress();
|
||||
|
||||
/**
|
||||
* Attempts to log on the server with the specified user name and password.
|
||||
*
|
||||
* @param user The user name
|
||||
* @param password The password for that user
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission
|
||||
* @throws FtpProtocolException if the login was refused by the server
|
||||
*/
|
||||
public abstract FtpClient login(String user, char[] password) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Attempts to log on the server with the specified user name, password and
|
||||
* account name.
|
||||
*
|
||||
* @param user The user name
|
||||
* @param password The password for that user.
|
||||
* @param account The account name for that user.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the login was refused by the server
|
||||
*/
|
||||
public abstract FtpClient login(String user, char[] password, String account) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Closes the current connection. Logs out the current user, if any, by
|
||||
* issuing the QUIT command to the server.
|
||||
* This is in effect terminates the current
|
||||
* session and the connection to the server will be closed.
|
||||
* <p>After a close, the client can then be connected to another server
|
||||
* to start an entirely different session.</P>
|
||||
*
|
||||
* @throws IOException if an error occurs during transmission
|
||||
*/
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Checks whether the client is logged in to the server or not.
|
||||
*
|
||||
* @return {@code true} if the client has already completed a login.
|
||||
*/
|
||||
public abstract boolean isLoggedIn();
|
||||
|
||||
/**
|
||||
* Changes to a specific directory on a remote FTP server
|
||||
*
|
||||
* @param remoteDirectory path of the directory to CD to.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was refused by the server
|
||||
*/
|
||||
public abstract FtpClient changeDirectory(String remoteDirectory) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Changes to the parent directory, sending the CDUP command to the server.
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was refused by the server
|
||||
*/
|
||||
public abstract FtpClient changeToParentDirectory() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Retrieve the server current working directory using the PWD command.
|
||||
*
|
||||
* @return a {@code String} containing the current working directory
|
||||
* @throws IOException if an error occurs during transmission
|
||||
* @throws FtpProtocolException if the command was refused by the server,
|
||||
*/
|
||||
public abstract String getWorkingDirectory() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sets the restart offset to the specified value. That value will be
|
||||
* sent through a {@code REST} command to server before the next file
|
||||
* transfer and has the effect of resuming a file transfer from the
|
||||
* specified point. After the transfer the restart offset is set back to
|
||||
* zero.
|
||||
*
|
||||
* @param 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.
|
||||
* @return this FtpClient
|
||||
* @throws IllegalArgumentException if the offset is negative.
|
||||
*/
|
||||
public abstract FtpClient setRestartOffset(long offset);
|
||||
|
||||
/**
|
||||
* Retrieves a file from the ftp server and writes its content to the specified
|
||||
* {@code OutputStream}.
|
||||
* <p>If the restart offset was set, then a {@code REST} command will be
|
||||
* sent before the {@code RETR} in order to restart the tranfer from the specified
|
||||
* offset.</p>
|
||||
* <p>The {@code OutputStream} is not closed by this method at the end
|
||||
* of the transfer. </p>
|
||||
* <p>This method will block until the transfer is complete or an exception
|
||||
* is thrown.</p>
|
||||
*
|
||||
* @param name a {@code String} containing the name of the file to
|
||||
* retreive from the server.
|
||||
* @param local the {@code OutputStream} the file should be written to.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if the transfer fails.
|
||||
* @throws FtpProtocolException if the command was refused by the server
|
||||
* @see #setRestartOffset(long)
|
||||
*/
|
||||
public abstract FtpClient getFile(String name, OutputStream local) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Retrieves a file from the ftp server, using the {@code RETR} command, and
|
||||
* returns the InputStream from the established data connection.
|
||||
* {@link #completePending()} <b>has</b> to be called once the application
|
||||
* is done reading from the returned stream.
|
||||
* <p>If the restart offset was set, then a {@code REST} command will be
|
||||
* sent before the {@code RETR} in order to restart the tranfer from the specified
|
||||
* offset.</p>
|
||||
*
|
||||
* @param name the name of the remote file
|
||||
* @return the {@link java.io.InputStream} from the data connection
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was refused by the server
|
||||
* @see #setRestartOffset(long)
|
||||
*/
|
||||
public abstract InputStream getFileStream(String name) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Transfers a file from the client to the server (aka a <I>put</I>)
|
||||
* by sending the STOR command, and returns the {@code OutputStream}
|
||||
* from the established data connection.
|
||||
*
|
||||
* A new file is created at the server site if the file specified does
|
||||
* not already exist.
|
||||
*
|
||||
* {@link #completePending()} <b>has</b> to be called once the application
|
||||
* is finished writing to the returned stream.
|
||||
*
|
||||
* @param name the name of the remote file to write.
|
||||
* @return the {@link java.io.OutputStream} from the data connection or
|
||||
* {@code null} if the command was unsuccessful.
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public OutputStream putFileStream(String name) throws FtpProtocolException, IOException {
|
||||
return putFileStream(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers a file from the client to the server (aka a <I>put</I>)
|
||||
* by sending the STOR or STOU command, depending on the
|
||||
* {@code unique} argument, and returns the {@code OutputStream}
|
||||
* from the established data connection.
|
||||
* {@link #completePending()} <b>has</b> 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 {@code unique} is set to {@code 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 {@link #getLastFileName()}.
|
||||
*
|
||||
* @param name the name of the remote file to write.
|
||||
* @param unique {@code true} if the remote files should be unique,
|
||||
* in which case the STOU command will be used.
|
||||
* @return the {@link java.io.OutputStream} from the data connection.
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract OutputStream putFileStream(String name, boolean unique) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Transfers a file from the client to the server (aka a <I>put</I>)
|
||||
* by sending the STOR or STOU command, depending on the
|
||||
* {@code unique} argument. The content of the {@code 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 {@code unique} is set to {@code 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 {@link #getLastFileName()}.
|
||||
*
|
||||
* <p>This method will block until the transfer is complete or an exception
|
||||
* is thrown.</p>
|
||||
*
|
||||
* @param name the name of the remote file to write.
|
||||
* @param local the {@code InputStream} that points to the data to
|
||||
* transfer.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public FtpClient putFile(String name, InputStream local) throws FtpProtocolException, IOException {
|
||||
return putFile(name, local, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers a file from the client to the server (aka a <I>put</I>)
|
||||
* by sending the STOR command. The content of the {@code 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.
|
||||
*
|
||||
* <p>This method will block until the transfer is complete or an exception
|
||||
* is thrown.</p>
|
||||
*
|
||||
* @param name the name of the remote file to write.
|
||||
* @param local the {@code InputStream} that points to the data to
|
||||
* transfer.
|
||||
* @param unique {@code true} if the remote file should be unique
|
||||
* (i.e. not already existing), {@code false} otherwise.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #getLastFileName()
|
||||
*/
|
||||
public abstract FtpClient putFile(String name, InputStream local, boolean unique) throws FtpProtocolException, 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.
|
||||
*
|
||||
* <p>This method will block until the transfer is complete or an exception
|
||||
* is thrown.</p>
|
||||
*
|
||||
* @param name A {@code String} containing the name of the remote file
|
||||
* to append to.
|
||||
* @param local The {@code InputStream} providing access to the data
|
||||
* to be appended.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient appendFile(String name, InputStream local) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Renames a file on the server.
|
||||
*
|
||||
* @param from the name of the file being renamed
|
||||
* @param to the new name for the file
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient rename(String from, String to) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Deletes a file on the server.
|
||||
*
|
||||
* @param name a {@code String} containing the name of the file
|
||||
* to delete.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the exchange
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient deleteFile(String name) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Creates a new directory on the server.
|
||||
*
|
||||
* @param name a {@code String} containing the name of the directory
|
||||
* to create.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the exchange
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient makeDirectory(String name) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Removes a directory on the server.
|
||||
*
|
||||
* @param name a {@code String} containing the name of the directory
|
||||
* to remove.
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the exchange.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient removeDirectory(String name) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends a No-operation command. It's useful for testing the connection
|
||||
* status or as a <I>keep alive</I> mechanism.
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient noop() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the {@code 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
|
||||
* {@code 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.
|
||||
*
|
||||
* @param name an optional {@code String} containing the pathname
|
||||
* the STAT command should apply to.
|
||||
* @return the response from the server
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract String getStatus(String name) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the {@code 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
|
||||
* a {@link FtpProtocolException} will be thrown.
|
||||
*
|
||||
* @return a {@code List} of {@code Strings} describing the
|
||||
* supported additional features
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command is rejected by the server
|
||||
*/
|
||||
public abstract List<String> getFeatures() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the {@code ABOR} command to the server.
|
||||
* <p>It tells the server to stop the previous command or transfer. No action
|
||||
* will be taken if the previous command has already been completed.</p>
|
||||
* <p>This doesn't abort the current session, more commands can be issued
|
||||
* after an abort.</p>
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient abort() throws FtpProtocolException, 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 {@link #getFileStream(String)}.
|
||||
* So this method should be called before accessing information related to
|
||||
* such a command.
|
||||
* <p>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).</p>
|
||||
* <p>Note that this will return immediately if no command or action
|
||||
* is pending</p>
|
||||
* <p>It should be also noted that most methods issuing commands to the ftp
|
||||
* server will call this method if a previous command is pending.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* InputStream in = cl.getFileStream("file");
|
||||
* ...
|
||||
* cl.completePending();
|
||||
* long size = cl.getLastTransferSize();
|
||||
* </pre>
|
||||
* On the other hand, it's not necessary in a case like:
|
||||
* <pre>
|
||||
* InputStream in = cl.getFileStream("file");
|
||||
* // read content
|
||||
* ...
|
||||
* cl.close();
|
||||
* </pre>
|
||||
* <p>Since {@link #close()} will call completePending() if necessary.</p>
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transfer
|
||||
* @throws FtpProtocolException if the command didn't complete successfully
|
||||
*/
|
||||
public abstract FtpClient completePending() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Reinitializes the USER parameters on the FTP server
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurs during transmission
|
||||
* @throws FtpProtocolException if the command fails
|
||||
*/
|
||||
public abstract FtpClient reInit() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Changes the transfer type (binary, ascii, ebcdic) and issue the
|
||||
* proper command (e.g. TYPE A) to the server.
|
||||
*
|
||||
* @param type the {@code TransferType} to use.
|
||||
* @return This FtpClient
|
||||
* @throws IOException if an error occurs during transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient setType(TransferType type) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Changes the current transfer type to binary.
|
||||
* This is a convenience method that is equivalent to
|
||||
* {@code setType(TransferType.BINARY)}
|
||||
*
|
||||
* @return This FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #setType(TransferType)
|
||||
*/
|
||||
public FtpClient setBinaryType() throws FtpProtocolException, IOException {
|
||||
setType(TransferType.BINARY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the current transfer type to ascii.
|
||||
* This is a convenience method that is equivalent to
|
||||
* {@code setType(TransferType.ASCII)}
|
||||
*
|
||||
* @return This FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #setType(TransferType)
|
||||
*/
|
||||
public FtpClient setAsciiType() throws FtpProtocolException, IOException {
|
||||
setType(TransferType.ASCII);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a {@code LIST} command to the server to get the current directory
|
||||
* listing, and returns the InputStream from the data connection.
|
||||
*
|
||||
* <p>{@link #completePending()} <b>has</b> to be called once the application
|
||||
* is finished reading from the stream.</p>
|
||||
*
|
||||
* @param path the pathname of the directory to list, or {@code null}
|
||||
* for the current working directory.
|
||||
* @return the {@code InputStream} from the resulting data connection
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #changeDirectory(String)
|
||||
* @see #listFiles(String)
|
||||
*/
|
||||
public abstract InputStream list(String path) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Issues a {@code NLST path} command to server to get the specified directory
|
||||
* content. It differs from {@link #list(String)} method by the fact that
|
||||
* it will only list the file names which would make the parsing of the
|
||||
* somewhat easier.
|
||||
*
|
||||
* <p>{@link #completePending()} <b>has</b> to be called once the application
|
||||
* is finished reading from the stream.</p>
|
||||
*
|
||||
* @param path a {@code String} containing the pathname of the
|
||||
* directory to list or {@code null} for the current working directory.
|
||||
* @return the {@code InputStream} from the resulting data connection
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract InputStream nameList(String path) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Issues the {@code 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.
|
||||
*
|
||||
* @param path a {@code String} containing the pathname of the
|
||||
* file.
|
||||
* @return a {@code long} containing the size of the file or -1 if
|
||||
* the server returned an error, which can be checked with
|
||||
* {@link #getLastReplyCode()}.
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract long getSize(String path) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Issues the {@code 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 {@code null} will be returned.
|
||||
*
|
||||
* @param path a {@code String} containing the pathname of the file.
|
||||
* @return a {@code Date} representing the last modification time
|
||||
* or {@code null} if the server returned an error, which
|
||||
* can be checked with {@link #getLastReplyCode()}.
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract Date getLastModified(String path) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param p The {@code FtpDirParser} to use.
|
||||
* @return this FtpClient
|
||||
* @see #listFiles(String)
|
||||
*/
|
||||
public abstract FtpClient setDirParser(FtpDirParser p);
|
||||
|
||||
/**
|
||||
* Issues a {@code MLSD} command to the server to get the specified directory
|
||||
* listing and applies the internal parser to create an Iterator of
|
||||
* {@link java.net.FtpDirEntry}. Note that the Iterator returned is also a
|
||||
* {@link java.io.Closeable}.
|
||||
* <p>If the server doesn't support the MLSD command, the LIST command is used
|
||||
* instead and the parser set by {@link #setDirParser(java.net.FtpDirParser) }
|
||||
* is used instead.</p>
|
||||
*
|
||||
* {@link #completePending()} <b>has</b> to be called once the application
|
||||
* is finished iterating through the files.
|
||||
*
|
||||
* @param path the pathname of the directory to list or {@code null}
|
||||
* for the current working directoty.
|
||||
* @return an {@code Iterator} of files or {@code null} if the
|
||||
* command failed.
|
||||
* @throws IOException if an error occurred during the transmission
|
||||
* @see #setDirParser(FtpDirParser)
|
||||
* @see #changeDirectory(String)
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract Iterator<FtpDirEntry> listFiles(String path) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Attempts to use Kerberos GSSAPI as an authentication mechanism with the
|
||||
* ftp server. This will issue an {@code AUTH GSSAPI} command, and if
|
||||
* it is accepted by the server, will followup with {@code ADAT}
|
||||
* command to exchange the various tokens until authentication is
|
||||
* successful. This conforms to Appendix I of RFC 2228.
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurs during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient useKerberos() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Returns the Welcome string the server sent during initial connection.
|
||||
*
|
||||
* @return a {@code String} containing the message the server
|
||||
* returned during connection or {@code null}.
|
||||
*/
|
||||
public abstract String getWelcomeMsg();
|
||||
|
||||
/**
|
||||
* Returns the last reply code sent by the server.
|
||||
*
|
||||
* @return the lastReplyCode or {@code null} if none were received yet.
|
||||
*/
|
||||
public abstract FtpReplyCode getLastReplyCode();
|
||||
|
||||
/**
|
||||
* Returns the last response string sent by the server.
|
||||
*
|
||||
* @return the message string, which can be quite long, last returned
|
||||
* by the server, or {@code null} if no response were received yet.
|
||||
*/
|
||||
public abstract String getLastResponseString();
|
||||
|
||||
/**
|
||||
* 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 {@code RETR} or similar request.
|
||||
*
|
||||
* @return the size of the latest transfer or -1 if either there was no
|
||||
* transfer or the information was unavailable.
|
||||
*/
|
||||
public abstract long getLastTransferSize();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return the name the latest transfered file remote name, or
|
||||
* {@code null} if that information is unavailable.
|
||||
*/
|
||||
public abstract String getLastFileName();
|
||||
|
||||
/**
|
||||
* Attempts to switch to a secure, encrypted connection. This is done by
|
||||
* sending the {@code AUTH TLS} command.
|
||||
* <p>See <a href="http://www.ietf.org/rfc/rfc4217.txt">RFC 4217</a></p>
|
||||
* 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
|
||||
* {@link #reInit()} command or a {@link #endSecureSession()} command is issued.
|
||||
* <p>This method should be called after a successful {@link #connect(java.net.InetSocketAddress) }
|
||||
* but before calling {@link #login(java.lang.String, char[]) }.</p>
|
||||
*
|
||||
* @return this FtpCLient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #endSecureSession()
|
||||
*/
|
||||
public abstract FtpClient startSecureSession() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends a {@code CCC} command followed by a {@code PROT C}
|
||||
* command to the server terminating an encrypted session and reverting
|
||||
* back to a non encrypted transmission.
|
||||
*
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
* @see #startSecureSession()
|
||||
*/
|
||||
public abstract FtpClient endSecureSession() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the "Allocate" ({@code ALLO}) command to the server telling it to
|
||||
* pre-allocate the specified number of bytes for the next transfer.
|
||||
*
|
||||
* @param size The number of bytes to allocate.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient allocate(long size) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the "Structure Mount" ({@code SMNT}) command to the server. This let the
|
||||
* user mount a different file system data structure without altering his
|
||||
* login or accounting information.
|
||||
*
|
||||
* @param struct a {@code String} containing the name of the
|
||||
* structure to mount.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient structureMount(String struct) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends a System ({@code SYST}) command to the server and returns the String
|
||||
* sent back by the server describing the operating system at the
|
||||
* server.
|
||||
*
|
||||
* @return a {@code String} describing the OS, or {@code null}
|
||||
* if the operation was not successful.
|
||||
* @throws IOException if an error occurred during the transmission.
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract String getSystem() throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the {@code HELP} command to the server, with an optional command, like
|
||||
* SITE, and returns the text sent back by the server.
|
||||
*
|
||||
* @param cmd the command for which the help is requested or
|
||||
* {@code null} for the general help
|
||||
* @return a {@code String} containing the text sent back by the
|
||||
* server, or {@code null} if the command failed.
|
||||
* @throws IOException if an error occurred during transmission
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract String getHelp(String cmd) throws FtpProtocolException, IOException;
|
||||
|
||||
/**
|
||||
* Sends the {@code SITE} command to the server. This is used by the server
|
||||
* to provide services specific to his system that are essential
|
||||
* to file transfer.
|
||||
*
|
||||
* @param cmd the command to be sent.
|
||||
* @return this FtpClient
|
||||
* @throws IOException if an error occurred during transmission
|
||||
* @throws FtpProtocolException if the command was rejected by the server
|
||||
*/
|
||||
public abstract FtpClient siteCmd(String cmd) throws FtpProtocolException, IOException;
|
||||
}
|
158
src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java
Normal file
158
src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ServiceConfigurationError;
|
||||
//import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* Service provider class for FtpClient.
|
||||
* Sub-classes of FtpClientProvider provide an implementation of {@link FtpClient}
|
||||
* and associated classes. Applications do not normally use this class directly.
|
||||
* See {@link #provider() } for how providers are found and loaded.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public abstract class FtpClientProvider {
|
||||
|
||||
/**
|
||||
* Creates a FtpClient from this provider.
|
||||
*
|
||||
* @return The created {@link FtpClient}.
|
||||
*/
|
||||
public abstract FtpClient createFtpClient();
|
||||
private static final Object lock = new Object();
|
||||
private static FtpClientProvider provider = null;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @throws SecurityException if a security manager is installed and it denies
|
||||
* {@link RuntimePermission}{@code ("ftpClientProvider")}
|
||||
*/
|
||||
protected FtpClientProvider() {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("ftpClientProvider"));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean loadProviderFromProperty() {
|
||||
String cm = System.getProperty("sun.net.ftpClientProvider");
|
||||
if (cm == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object o = Class.forName(cm, true, null).newInstance();
|
||||
provider = (FtpClientProvider)o;
|
||||
return true;
|
||||
} catch (ClassNotFoundException |
|
||||
IllegalAccessException |
|
||||
InstantiationException |
|
||||
SecurityException x) {
|
||||
throw new ServiceConfigurationError(x.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean loadProviderAsService() {
|
||||
// Iterator<FtpClientProvider> i =
|
||||
// ServiceLoader.load(FtpClientProvider.class,
|
||||
// ClassLoader.getSystemClassLoader()).iterator();
|
||||
//
|
||||
// while (i.hasNext()) {
|
||||
// try {
|
||||
// provider = i.next();
|
||||
// return true;
|
||||
// } catch (ServiceConfigurationError sce) {
|
||||
// if (sce.getCause() instanceof SecurityException) {
|
||||
// // Ignore, try next provider, if any
|
||||
// continue;
|
||||
// }
|
||||
// throw sce;
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system wide default FtpClientProvider for this invocation of
|
||||
* the Java virtual machine.
|
||||
*
|
||||
* <p> The first invocation of this method locates the default provider
|
||||
* object as follows: </p>
|
||||
*
|
||||
* <ol>
|
||||
*
|
||||
* <li><p> If the system property
|
||||
* {@code java.net.FtpClientProvider} is defined then it is
|
||||
* taken to be the fully-qualified name of a concrete provider class.
|
||||
* The class is loaded and instantiated; if this process fails then an
|
||||
* unspecified unchecked error or exception is thrown. </p></li>
|
||||
*
|
||||
* <li><p> If a provider class has been installed in a jar file that is
|
||||
* visible to the system class loader, and that jar file contains a
|
||||
* provider-configuration file named
|
||||
* {@code java.net.FtpClientProvider} in the resource
|
||||
* directory {@code META-INF/services}, then the first class name
|
||||
* specified in that file is taken. The class is loaded and
|
||||
* instantiated; if this process fails then an unspecified unchecked error or exception is
|
||||
* thrown. </p></li>
|
||||
*
|
||||
* <li><p> Finally, if no provider has been specified by any of the above
|
||||
* means then the system-default provider class is instantiated and the
|
||||
* result is returned. </p></li>
|
||||
*
|
||||
* </ol>
|
||||
*
|
||||
* <p> Subsequent invocations of this method return the provider that was
|
||||
* returned by the first invocation. </p>
|
||||
*
|
||||
* @return The system-wide default FtpClientProvider
|
||||
*/
|
||||
public static FtpClientProvider provider() {
|
||||
synchronized (lock) {
|
||||
if (provider != null) {
|
||||
return provider;
|
||||
}
|
||||
return (FtpClientProvider) AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
|
||||
public Object run() {
|
||||
if (loadProviderFromProperty()) {
|
||||
return provider;
|
||||
}
|
||||
if (loadProviderAsService()) {
|
||||
return provider;
|
||||
}
|
||||
provider = new sun.net.ftp.impl.DefaultFtpClientProvider();
|
||||
return provider;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
331
src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java
Normal file
331
src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java
Normal file
|
@ -0,0 +1,331 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A {@code FtpDirEntry} is a class agregating all the information that the FTP client
|
||||
* can gather from the server by doing a {@code LST} (or {@code NLST}) command and
|
||||
* parsing the output. It will typically contain the name, type, size, last modification
|
||||
* time, owner and group of the file, although some of these could be unavailable
|
||||
* due to specific FTP server limitations.
|
||||
*
|
||||
* @see sun.net.ftp.FtpDirParser
|
||||
* @since 1.7
|
||||
*/
|
||||
public class FtpDirEntry {
|
||||
|
||||
public enum Type {
|
||||
|
||||
FILE, DIR, PDIR, CDIR, LINK
|
||||
};
|
||||
|
||||
public enum Permission {
|
||||
|
||||
USER(0), GROUP(1), OTHERS(2);
|
||||
int value;
|
||||
|
||||
Permission(int v) {
|
||||
value = v;
|
||||
}
|
||||
};
|
||||
private final String name;
|
||||
private String user = null;
|
||||
private String group = null;
|
||||
private long size = -1;
|
||||
private java.util.Date created = null;
|
||||
private java.util.Date lastModified = null;
|
||||
private Type type = Type.FILE;
|
||||
private boolean[][] permissions = null;
|
||||
private HashMap<String, String> facts = new HashMap<String, String>();
|
||||
|
||||
private FtpDirEntry() {
|
||||
name = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an FtpDirEntry instance with only the name being set.
|
||||
*
|
||||
* @param name The name of the file
|
||||
*/
|
||||
public FtpDirEntry(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the remote file.
|
||||
*
|
||||
* @return a {@code String} containing the name of the remote file.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user name of the owner of the file as returned by the FTP
|
||||
* server, if provided. This could be a name or a user id (number).
|
||||
*
|
||||
* @return a {@code String} containing the user name or
|
||||
* {@code null} if that information is not available.
|
||||
*/
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user name of the owner of the file. Intended mostly to be
|
||||
* used from inside a {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param user The user name of the owner of the file, or {@code null}
|
||||
* if that information is not available.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setUser(String user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group name of the file as returned by the FTP
|
||||
* server, if provided. This could be a name or a group id (number).
|
||||
*
|
||||
* @return a {@code String} containing the group name or
|
||||
* {@code null} if that information is not available.
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the group to which the file belong. Intended mostly to be
|
||||
* used from inside a {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param group The name of the group to which the file belong, or {@code null}
|
||||
* if that information is not available.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the remote file as it was returned by the FTP
|
||||
* server, if provided.
|
||||
*
|
||||
* @return the size of the file or -1 if that information is not available.
|
||||
*/
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of that file. Intended mostly to be used from inside an
|
||||
* {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param size The size, in bytes, of that file. or -1 if unknown.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setSize(long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the remote file as it was returned by the FTP
|
||||
* server, if provided.
|
||||
* It returns a FtpDirEntry.Type enum and the values can be:
|
||||
* - FtpDirEntry.Type.FILE for a normal file
|
||||
* - FtpDirEntry.Type.DIR for a directory
|
||||
* - FtpDirEntry.Type.LINK for a symbolic link
|
||||
*
|
||||
* @return a {@code FtpDirEntry.Type} describing the type of the file
|
||||
* or {@code null} if that information is not available.
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the file. Intended mostly to be used from inside an
|
||||
* {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param type the type of this file or {@code null} if that information
|
||||
* is not available.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setType(Type type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last modification time of the remote file as it was returned
|
||||
* by the FTP server, if provided, {@code null} otherwise.
|
||||
*
|
||||
* @return a <code>Date</code> representing the last time the file was
|
||||
* modified on the server, or {@code null} if that
|
||||
* information is not available.
|
||||
*/
|
||||
public java.util.Date getLastModified() {
|
||||
return this.lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last modification time of the file. Intended mostly to be used
|
||||
* from inside an {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param lastModified The Date representing the last modification time, or
|
||||
* {@code null} if that information is not available.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setLastModified(Date lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether read access is granted for a specific permission.
|
||||
*
|
||||
* @param p the Permission (user, group, others) to check.
|
||||
* @return {@code true} if read access is granted.
|
||||
*/
|
||||
public boolean canRead(Permission p) {
|
||||
if (permissions != null) {
|
||||
return permissions[p.value][0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether write access is granted for a specific permission.
|
||||
*
|
||||
* @param p the Permission (user, group, others) to check.
|
||||
* @return {@code true} if write access is granted.
|
||||
*/
|
||||
public boolean canWrite(Permission p) {
|
||||
if (permissions != null) {
|
||||
return permissions[p.value][1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether execute access is granted for a specific permission.
|
||||
*
|
||||
* @param p the Permission (user, group, others) to check.
|
||||
* @return {@code true} if execute access is granted.
|
||||
*/
|
||||
public boolean canExexcute(Permission p) {
|
||||
if (permissions != null) {
|
||||
return permissions[p.value][2];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the permissions for that file. Intended mostly to be used
|
||||
* from inside an {@link java.net.FtpDirParser} implementation.
|
||||
* The permissions array is a 3x3 {@code boolean} array, the first index being
|
||||
* the User, group or owner (0, 1 and 2 respectively) while the second
|
||||
* index is read, write or execute (0, 1 and 2 respectively again).
|
||||
* <p>E.G.: {@code permissions[1][2]} is the group/execute permission.</p>
|
||||
*
|
||||
* @param permissions a 3x3 {@code boolean} array
|
||||
* @return this {@code FtpDirEntry}
|
||||
*/
|
||||
public FtpDirEntry setPermissions(boolean[][] permissions) {
|
||||
this.permissions = permissions;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'fact', as defined in RFC 3659, to the list of facts of this file.
|
||||
* Intended mostly to be used from inside a {@link java.net.FtpDirParser}
|
||||
* implementation.
|
||||
*
|
||||
* @param fact the name of the fact (e.g. "Media-Type"). It is not case-sensitive.
|
||||
* @param value the value associated with this fact.
|
||||
* @return this {@code FtpDirEntry}
|
||||
*/
|
||||
public FtpDirEntry addFact(String fact, String value) {
|
||||
facts.put(fact.toLowerCase(), value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requested 'fact', as defined in RFC 3659, if available.
|
||||
*
|
||||
* @param fact The name of the fact *e.g. "Media-Type"). It is not case sensitive.
|
||||
* @return The value of the fact or, {@code null} if that fact wasn't
|
||||
* provided by the server.
|
||||
*/
|
||||
public String getFact(String fact) {
|
||||
return facts.get(fact.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the creation time of the file, when provided by the server.
|
||||
*
|
||||
* @return The Date representing the creation time, or {@code null}
|
||||
* if the server didn't provide that information.
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the creation time for that file. Intended mostly to be used from
|
||||
* inside a {@link java.net.FtpDirParser} implementation.
|
||||
*
|
||||
* @param created the Date representing the creation time for that file, or
|
||||
* {@code null} if that information is not available.
|
||||
* @return this FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry setCreated(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* The {@code toString} method for class {@code FtpDirEntry}
|
||||
* returns a string consisting of the name of the file, followed by its
|
||||
* type between brackets, followed by the user and group between
|
||||
* parenthesis, then size between '{', and, finally, the lastModified of last
|
||||
* modification if it's available.
|
||||
*
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (lastModified == null) {
|
||||
return name + " [" + type + "] (" + user + " / " + group + ") " + size;
|
||||
}
|
||||
return name + " [" + type + "] (" + user + " / " + group + ") {" + size + "} " + java.text.DateFormat.getDateInstance().format(lastModified);
|
||||
}
|
||||
}
|
49
src/java.base/share/classes/sun/net/ftp/FtpDirParser.java
Normal file
49
src/java.base/share/classes/sun/net/ftp/FtpDirParser.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.ftp;
|
||||
|
||||
/**
|
||||
* This interface describes a parser for the FtpClient class. Such a parser is
|
||||
* used when listing a remote directory to transform text lines like:
|
||||
* drwxr-xr-x 1 user01 ftp 512 Jan 29 23:32 prog
|
||||
* into FtpDirEntry instances.
|
||||
*
|
||||
* @see java.net.FtpClient#setFileParser(FtpDirParser)
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface FtpDirParser {
|
||||
|
||||
/**
|
||||
* Takes one line from a directory listing and returns an FtpDirEntry instance
|
||||
* based on the information contained.
|
||||
*
|
||||
* @param line a <code>String</code>, a line sent by the FTP server as a
|
||||
* result of the LST command.
|
||||
* @return an <code>FtpDirEntry</code> instance.
|
||||
* @see java.net.FtpDirEntry
|
||||
*/
|
||||
public FtpDirEntry parseLine(String line);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.net.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an error is encountered during an
|
||||
* FTP login operation.
|
||||
*
|
||||
* @author Jonathan Payne
|
||||
*/
|
||||
public class FtpLoginException extends IOException {
|
||||
private static final long serialVersionUID = 2218162403237941536L;
|
||||
|
||||
public FtpLoginException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that the FTP server reported an error.
|
||||
* For instance that the requested file doesn't exist or
|
||||
* that a command isn't supported.
|
||||
* <p>The specific error code can be retreived with {@link #getReplyCode() }.</p>
|
||||
* @author Jonathan Payne
|
||||
*/
|
||||
public class FtpProtocolException extends Exception {
|
||||
private static final long serialVersionUID = 5978077070276545054L;
|
||||
private final FtpReplyCode code;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FtpProtocolException} from the
|
||||
* specified detail message. The reply code is set to unknow error.
|
||||
*
|
||||
* @param detail the detail message.
|
||||
*/
|
||||
public FtpProtocolException(String detail) {
|
||||
super(detail);
|
||||
code = FtpReplyCode.UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FtpProtocolException} from the
|
||||
* specified response code and exception detail message
|
||||
*
|
||||
* @param detail the detail message.
|
||||
* @param code The {@code FtpRelyCode} received from server.
|
||||
*/
|
||||
public FtpProtocolException(String detail, FtpReplyCode code) {
|
||||
super(detail);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reply code sent by the server that led to this exception
|
||||
* being thrown.
|
||||
*
|
||||
* @return The {@link FtpReplyCode} associated with that exception.
|
||||
*/
|
||||
public FtpReplyCode getReplyCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
248
src/java.base/share/classes/sun/net/ftp/FtpReplyCode.java
Normal file
248
src/java.base/share/classes/sun/net/ftp/FtpReplyCode.java
Normal file
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp;
|
||||
|
||||
/**
|
||||
* This class describes a FTP protocol reply code and associates a meaning
|
||||
* to the numerical value according to the various RFCs (RFC 959 in
|
||||
* particular).
|
||||
*
|
||||
*/
|
||||
public enum FtpReplyCode {
|
||||
|
||||
RESTART_MARKER(110),
|
||||
SERVICE_READY_IN(120),
|
||||
DATA_CONNECTION_ALREADY_OPEN(125),
|
||||
FILE_STATUS_OK(150),
|
||||
COMMAND_OK(200),
|
||||
NOT_IMPLEMENTED(202),
|
||||
SYSTEM_STATUS(211),
|
||||
DIRECTORY_STATUS(212),
|
||||
FILE_STATUS(213),
|
||||
HELP_MESSAGE(214),
|
||||
NAME_SYSTEM_TYPE(215),
|
||||
SERVICE_READY(220),
|
||||
SERVICE_CLOSING(221),
|
||||
DATA_CONNECTION_OPEN(225),
|
||||
CLOSING_DATA_CONNECTION(226),
|
||||
ENTERING_PASSIVE_MODE(227),
|
||||
ENTERING_EXT_PASSIVE_MODE(229),
|
||||
LOGGED_IN(230),
|
||||
SECURELY_LOGGED_IN(232),
|
||||
SECURITY_EXCHANGE_OK(234),
|
||||
SECURITY_EXCHANGE_COMPLETE(235),
|
||||
FILE_ACTION_OK(250),
|
||||
PATHNAME_CREATED(257),
|
||||
NEED_PASSWORD(331),
|
||||
NEED_ACCOUNT(332),
|
||||
NEED_ADAT(334),
|
||||
NEED_MORE_ADAT(335),
|
||||
FILE_ACTION_PENDING(350),
|
||||
SERVICE_NOT_AVAILABLE(421),
|
||||
CANT_OPEN_DATA_CONNECTION(425),
|
||||
CONNECTION_CLOSED(426),
|
||||
NEED_SECURITY_RESOURCE(431),
|
||||
FILE_ACTION_NOT_TAKEN(450),
|
||||
ACTION_ABORTED(451),
|
||||
INSUFFICIENT_STORAGE(452),
|
||||
COMMAND_UNRECOGNIZED(500),
|
||||
INVALID_PARAMETER(501),
|
||||
BAD_SEQUENCE(503),
|
||||
NOT_IMPLEMENTED_FOR_PARAMETER(504),
|
||||
NOT_LOGGED_IN(530),
|
||||
NEED_ACCOUNT_FOR_STORING(532),
|
||||
PROT_LEVEL_DENIED(533),
|
||||
REQUEST_DENIED(534),
|
||||
FAILED_SECURITY_CHECK(535),
|
||||
UNSUPPORTED_PROT_LEVEL(536),
|
||||
PROT_LEVEL_NOT_SUPPORTED_BY_SECURITY(537),
|
||||
FILE_UNAVAILABLE(550),
|
||||
PAGE_TYPE_UNKNOWN(551),
|
||||
EXCEEDED_STORAGE(552),
|
||||
FILE_NAME_NOT_ALLOWED(553),
|
||||
PROTECTED_REPLY(631),
|
||||
UNKNOWN_ERROR(999);
|
||||
private final int value;
|
||||
|
||||
FtpReplyCode(int val) {
|
||||
this.value = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numerical value of the code.
|
||||
*
|
||||
* @return the numerical value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a Positive Preliminary response.
|
||||
* This means beginning with a 1 (which means a value between 100 and 199)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a positive preliminary
|
||||
* response.
|
||||
*/
|
||||
public boolean isPositivePreliminary() {
|
||||
return value >= 100 && value < 200;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a Positive Completion response.
|
||||
* This means beginning with a 2 (which means a value between 200 and 299)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a positive completion
|
||||
* response.
|
||||
*/
|
||||
public boolean isPositiveCompletion() {
|
||||
return value >= 200 && value < 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a positive internediate response.
|
||||
* This means beginning with a 3 (which means a value between 300 and 399)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a positive intermediate
|
||||
* response.
|
||||
*/
|
||||
public boolean isPositiveIntermediate() {
|
||||
return value >= 300 && value < 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a transient negative response.
|
||||
* This means beginning with a 4 (which means a value between 400 and 499)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a transient negative
|
||||
* response.
|
||||
*/
|
||||
public boolean isTransientNegative() {
|
||||
return value >= 400 && value < 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a permanent negative response.
|
||||
* This means beginning with a 5 (which means a value between 500 and 599)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a permanent negative
|
||||
* response.
|
||||
*/
|
||||
public boolean isPermanentNegative() {
|
||||
return value >= 500 && value < 600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a protected reply response.
|
||||
* This means beginning with a 6 (which means a value between 600 and 699)
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a protected reply
|
||||
* response.
|
||||
*/
|
||||
public boolean isProtectedReply() {
|
||||
return value >= 600 && value < 700;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a syntax related response.
|
||||
* This means the second digit is a 0.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a syntax related
|
||||
* response.
|
||||
*/
|
||||
public boolean isSyntax() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is an information related response.
|
||||
* This means the second digit is a 1.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is an information related
|
||||
* response.
|
||||
*/
|
||||
public boolean isInformation() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a connection related response.
|
||||
* This means the second digit is a 2.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a connection related
|
||||
* response.
|
||||
*/
|
||||
public boolean isConnection() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is an authentication related response.
|
||||
* This means the second digit is a 3.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is an authentication related
|
||||
* response.
|
||||
*/
|
||||
public boolean isAuthentication() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is an unspecified type of response.
|
||||
* This means the second digit is a 4.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is an unspecified type of
|
||||
* response.
|
||||
*/
|
||||
public boolean isUnspecified() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the code is a file system related response.
|
||||
* This means the second digit is a 5.
|
||||
*
|
||||
* @return <code>true</code> if the reply code is a file system related
|
||||
* response.
|
||||
*/
|
||||
public boolean isFileSystem() {
|
||||
return ((value / 10) - ((value / 100) * 10)) == 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static utility method to convert a value into a FtpReplyCode.
|
||||
*
|
||||
* @param v the value to convert
|
||||
* @return the <code>FtpReplyCode</code> associated with the value.
|
||||
*/
|
||||
public static FtpReplyCode find(int v) {
|
||||
for (FtpReplyCode code : FtpReplyCode.values()) {
|
||||
if (code.getValue() == v) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.net.ftp.impl;
|
||||
|
||||
/**
|
||||
* Default FtpClientProvider.
|
||||
* Uses sun.net.ftp.FtpCLient.
|
||||
*/
|
||||
public class DefaultFtpClientProvider extends sun.net.ftp.FtpClientProvider {
|
||||
|
||||
@Override
|
||||
public sun.net.ftp.FtpClient createFtpClient() {
|
||||
return sun.net.ftp.impl.FtpClient.create();
|
||||
}
|
||||
|
||||
}
|
2222
src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java
Normal file
2222
src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue