APIdia Launch Partner
Top Inners Fields Constructors Methods
sun.net.ftp.impl

public Class FtpClient

extends FtpClient
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .BufferedReader, .Closeable, .FileNotFoundException, .IOException, .InputStream, .InputStreamReader, .OutputStream, .PrintStream, .UnsupportedEncodingException, java.net.Inet6Address, .InetAddress, .InetSocketAddress, .Proxy, .ServerSocket, .Socket, .SocketAddress, java.text.DateFormat, java.time.ZoneOffset, .ZonedDateTime, java.time.format.DateTimeFormatter, .DateTimeParseException, java.util.ArrayList, .Arrays, .Base64, .Calendar, .Date, .Iterator, .List, .Vector, java.util.regex.Matcher, .Pattern, javax.net.ssl.SSLSocket, .SSLSocketFactory, sun.net.ftp.FtpDirEntry, .FtpDirParser, .FtpProtocolException, .FtpReplyCode, sun.net.util.IPAddressUtil, sun.util.logging.PlatformLogger

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final boolean
private int
private static int
private static int
private DateFormat
private static String
private static Pattern
pack-priv static final String
private InputStream
private String
private FtpReplyCode
lastReplyCode

The last reply code from the ftp daemon.

private long
private static Pattern
private boolean
private static final PlatformLogger
private FtpDirParser
private Socket
private PrintStream
private FtpDirParser
private final boolean
passiveMode

Only passive mode used in JDK.

private static Pattern
private static String[]
patStrings

Static members used by the parser

private static int[][]
private static Pattern[]
private Proxy
private int
private boolean
private long
private static final DateTimeFormatter
private Socket
private InetSocketAddress
serverAddr

remember the ftp server name because we may need it

private Vector<String>
serverResponse

Array of strings (usually 1 entry) for the last reply from the server.

private SSLSocketFactory
private static Pattern
private FtpClient.TransferType
private boolean
private String
welcomeMsg

Welcome message from the server, if any.

Constructor Summary

AccessConstructor and Description
protected
FtpClient()

Creates an instance of FtpClient.

Method Summary

Modifier and TypeMethod and Description
public FtpClient

Returns:

true if the command was successful.
abort
()

Implements abstract sun.net.ftp.FtpClient.abort.

sends the ABOR command to the server.

public FtpClient

Returns:

true if the operation was successful.
allocate
(long
The number of bytes to allocate.
size
)

Implements abstract sun.net.ftp.FtpClient.allocate.

Sends the "Allocate" (ALLO) command to the server telling it to pre-allocate the specified number of bytes for the next transfer.

public FtpClient

Returns:

true if the transfer was successful.
appendFile
(String
A String containing the name of the remote file to append to.
name
,
InputStream
The InputStream providing access to the data to be appended.
local
)

Implements abstract sun.net.ftp.FtpClient.appendFile.

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.

public FtpClient

Returns:

true if the operation was successful.
changeDirectory
(String
path of the directory to CD to.
remoteDirectory
)

Implements abstract sun.net.ftp.FtpClient.changeDirectory.

Changes to a specific directory on a remote FTP server

public FtpClient

Returns:

true if the command was successful.
changeToParentDirectory
()

Implements abstract sun.net.ftp.FtpClient.changeToParentDirectory.

Changes to the parent directory, sending the CDUP command to the server.

public void
close()

Implements abstract sun.net.ftp.FtpClient.close.

Implements java.io.Closeable.close.

Logs out the current user.

public FtpClient

Returns:

true if the completion was successful or if no action was pending.
completePending
()

Implements abstract sun.net.ftp.FtpClient.completePending.

Some methods do not wait until completion before returning, so this method can be called to wait until completion.

public FtpClient
connect(SocketAddress dest)

Implements abstract sun.net.ftp.FtpClient.connect.

Connects the FtpClient to the specified destination server.

public FtpClient
connect(SocketAddress
the address of the destination server
dest
,
int timeout)

Implements abstract sun.net.ftp.FtpClient.connect.

Connects the FtpClient to the specified destination.

public static FtpClient
create()

Hides sun.net.ftp.FtpClient.create.

Creates an instance of FtpClient.

private InputStream
private OutputStream
public FtpClient

Returns:

true if the command was successful
deleteFile
(String
a String containing the name of the file to delete.
name
)

Implements abstract sun.net.ftp.FtpClient.deleteFile.

Deletes a file on the server.

private void
private Socket
doConnect(InetSocketAddress dest, int timeout)

public FtpClient

Returns:

This FtpClient
enablePassiveMode
(boolean passive)

Implements abstract sun.net.ftp.FtpClient.enablePassiveMode.

Set the transfer mode to passive.

public FtpClient

Returns:

true if the operation was successful.
endSecureSession
()

Implements abstract sun.net.ftp.FtpClient.endSecureSession.

Sends a CCC command followed by a PROT C command to the server terminating an encrypted session and reverting back to a non encrypted transmission.

private static InetAddress[]
getAllByName(String hostName)

public int

Returns:

the value, in milliseconds, of the current connect timeout.
getConnectTimeout
()

Implements abstract sun.net.ftp.FtpClient.getConnectTimeout.

Returns the current connection timeout value.

public List<String>

Returns:

a List of Strings describing the supported additional features, or null if the command is not supported.
getFeatures
()

Implements abstract sun.net.ftp.FtpClient.getFeatures.

Sends the FEAT command to the server and returns the list of supported features in the form of strings.

public FtpClient
getFile(String
a String containing the name of the file to retrieve from the server.
name
,
OutputStream
the OutputStream the file should be written to.
local
)

Implements abstract sun.net.ftp.FtpClient.getFile.

Retrieves a file from the ftp server and writes it to the specified OutputStream.

public InputStream

Returns:

the java.io.InputStream from the data connection, or null if the command was unsuccessful.
getFileStream
(String
the name of the remote file
name
)

Implements abstract sun.net.ftp.FtpClient.getFileStream.

Retrieves a file from the ftp server, using the RETR command, and returns the InputStream from* the established data connection.

public String

Returns:

a String containing the text sent back by the server, or null if the command failed.
getHelp
(String
the command for which the help is requested or null for the general help
cmd
)

Implements abstract sun.net.ftp.FtpClient.getHelp.

Sends the HELP command to the server, with an optional command, like SITE, and returns the text sent back by the server.

public String

Returns:

the name the latest transferred file remote name, or null if that information is unavailable.
getLastFileName
()

Implements abstract sun.net.ftp.FtpClient.getLastFileName.

Returns, when available, the remote name of the last transferred file.

public Date

Returns:

a Date representing the last modification time or null if the server returned an error, which can be checked with getLastReplyCode().
getLastModified
(String
a String containing the pathname of the file.
path
)

Implements abstract sun.net.ftp.FtpClient.getLastModified.

Issues the MDTM [path] command to the server to get the modification time of a specific file on the server.

public FtpReplyCode

Returns:

the lastReplyCode
getLastReplyCode
()

Implements abstract sun.net.ftp.FtpClient.getLastReplyCode.

Returns the last reply code sent by the server.

public String

Returns:

the message string, which can be quite long, last returned by the server.
getLastResponseString
()

Implements abstract sun.net.ftp.FtpClient.getLastResponseString.

Returns the last response string sent by the server.

public long

Returns:

the size of the latest transfer or -1 if either there was no transfer or the information was unavailable.
getLastTransferSize
()

Implements abstract sun.net.ftp.FtpClient.getLastTransferSize.

Returns, when available, the size of the latest started transfer.

private static InetAddress
public Proxy

Returns:

the Proxy, this client is using, or null if none is used.
getProxy
()

Implements abstract sun.net.ftp.FtpClient.getProxy.

Get the proxy of this FtpClient

public int

Returns:

the value, in milliseconds, of the current read timeout.
getReadTimeout
()

Implements abstract sun.net.ftp.FtpClient.getReadTimeout.

Returns the current read timeout value.

private String
getResponseString()

converts the server response into a string.

private Vector<String>
getResponseStrings()

Returns all server response strings.

private byte[]
public SocketAddress
getServerAddress()

Implements abstract sun.net.ftp.FtpClient.getServerAddress.

Retrieves the address of the FTP server this client is connected to.

public long

Returns:

a long containing the size of the file or -1 if the server returned an error, which can be checked with getLastReplyCode().
getSize
(String
a String containing the pathname of the file.
path
)

Implements abstract sun.net.ftp.FtpClient.getSize.

Issues the SIZE [path] command to the server to get the size of a specific file on the server.

public String

Returns:

the response from the server or null if the command failed.
getStatus
(String
an optional String containing the pathname the STAT command should apply to.
name
)

Implements abstract sun.net.ftp.FtpClient.getStatus.

Sends the STAT command to the server.

public String

Returns:

a String describing the OS, or null if the operation was not successful.
getSystem
()

Implements abstract sun.net.ftp.FtpClient.getSystem.

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

private void
getTransferName()

extract the created file name from the response string: 226 Transfer complete (unique file name:toto.txt.1).

private void
public String

Returns:

a String containing the message the server returned during connection or null.
getWelcomeMsg
()

Implements abstract sun.net.ftp.FtpClient.getWelcomeMsg.

Returns the Welcome string the server sent during initial connection.

public String

Returns:

a String containing the current working directory, or null
getWorkingDirectory
()

Implements abstract sun.net.ftp.FtpClient.getWorkingDirectory.

Returns the server current working directory, or null if the PWD command failed.

private static boolean
isASCIISuperset(String encoding)

Test the named character encoding to verify that it converts ASCII characters correctly.

public boolean

Returns:

true if the client is connected.
isConnected
()

Implements abstract sun.net.ftp.FtpClient.isConnected.

Tests whether this client is connected or not to a server.

public boolean

Returns:

true if the client has already completed a login.
isLoggedIn
()

Implements abstract sun.net.ftp.FtpClient.isLoggedIn.

Checks whether the client is logged in to the server or not.

public boolean

Returns:

the current FtpTransferMode
isPassiveModeEnabled
()

Implements abstract sun.net.ftp.FtpClient.isPassiveModeEnabled.

Gets the current transfer mode.

private boolean

Returns:

true if the command was successful
issueCommand
(String cmd)

Sends a command to the FTP server and returns the error code (which can be a "success") sent by the server.

private void
issueCommandCheck(String
String containing the command
cmd
)

Send a command to the FTP server and check for success.

public InputStream

Returns:

the InputStream from the resulting data connection
list
(String
the pathname of the directory to list, or null for the current working directory.
path
)

Implements abstract sun.net.ftp.FtpClient.list.

Issues a LIST command to the server to get the current directory listing, and returns the InputStream from the data connection.

public Iterator<FtpDirEntry>

Returns:

a Iterator of files or null if the command failed.
listFiles
(String
the pathname of the directory to list or null for the current working directory.
path
)

Implements abstract sun.net.ftp.FtpClient.listFiles.

Issues a MLSD command to the server to get the specified directory listing and applies the current parser to create an Iterator of java.net.ftp.FtpDirEntry.

public FtpClient

Returns:

true if the login was successful.
login
(String
The user name
user
,
char[]
The password for that user
password
)

Implements abstract sun.net.ftp.FtpClient.login.

Attempts to log on the server with the specified user name and password.

public FtpClient

Returns:

true if the login was successful.
login
(String
The user name
user
,
char[]
The password for that user.
password
,
String
The account name for that user.
account
)

Implements abstract sun.net.ftp.FtpClient.login.

Attempts to log on the server with the specified user name, password and account name.

public FtpClient

Returns:

true if the operation was successful.
makeDirectory
(String
a String containing the name of the directory to create.
name
)

Implements abstract sun.net.ftp.FtpClient.makeDirectory.

Creates a new directory on the server.

public InputStream

Returns:

the InputStream from the resulting data connection
nameList
(String
a String containing the pathname of the directory to list or null for the current working directory.
path
)

Implements abstract sun.net.ftp.FtpClient.nameList.

Issues a NLST path command to server to get the specified directory content.

public FtpClient
noop()

Implements abstract sun.net.ftp.FtpClient.noop.

Sends a No-operation command.

private Socket

Returns:

the connected Socket
openDataConnection
(String
the String containing the command to execute
cmd
)

Opens a data connection with the server according to the set mode (ACTIVE or PASSIVE) then send the command passed as an argument.

private Socket

Returns:

the connected Socket
openPassiveDataConnection
(String cmd)

Opens a "PASSIVE" connection with the server and returns the connected Socket.

private static Date
public FtpClient

Returns:

true if the transfer was successful.
putFile
(String
the name of the remote file to write.
name
,
InputStream
the InputStream that points to the data to transfer.
local
,
boolean
true if the remote file should be unique (i.e. not already existing), false otherwise.
unique
)

Implements abstract sun.net.ftp.FtpClient.putFile.

Transfers a file from the client to the server (aka a put) by sending the STOR command.

public OutputStream

Returns:

the java.io.OutputStream from the data connection or null if the command was unsuccessful.
putFileStream
(String
the name of the remote file to write.
name
,
boolean
true if the remote files should be unique, in which case the STOU command will be used.
unique
)

Implements abstract sun.net.ftp.FtpClient.putFileStream.

Transfers a file from the client to the server (aka a put) by sending the STOR or STOU command, depending on the unique argument, and returns the OutputStream from the established data connection.

private boolean

Returns:

true if the command was successful
readReply
()

Read the reply from the FTP server.

private int
readServerResponse()

Pulls the response from the server and returns the code as a number.

public FtpClient
reInit()

Implements abstract sun.net.ftp.FtpClient.reInit.

Reinitializes the USER parameters on the FTP server

public FtpClient

Returns:

true if the operation was successful.
removeDirectory
(String
a String containing the name of the directory to remove.
name
)

Implements abstract sun.net.ftp.FtpClient.removeDirectory.

Removes a directory on the server.

public FtpClient
rename(String
the name of the file being renamed
from
,
String
the new name for the file
to
)

Implements abstract sun.net.ftp.FtpClient.rename.

Renames a file on the server.

private boolean
sendSecurityData(byte[] buf)

private void
sendServer(String cmd)

Sends command cmd to the server.

public FtpClient

Returns:

This FtpClient
setConnectTimeout
(int
the timeout value, in milliseconds, to use for the connect operation. A value of zero or less, means use the default timeout.
timeout
)

Implements abstract sun.net.ftp.FtpClient.setConnectTimeout.

Sets the timeout value to use when connecting to the server,

public FtpClient
setDirParser(FtpDirParser
The FtpDirParser to use.
p
)

Implements abstract sun.net.ftp.FtpClient.setDirParser.

Sets the parser used to handle the directory output to the specified one.

public FtpClient
setProxy(Proxy p)

Implements abstract sun.net.ftp.FtpClient.setProxy.

Set the Proxy to be used for the next connection.

public FtpClient

Returns:

This FtpClient
setReadTimeout
(int
the timeout value, in milliseconds, to use for the read operation. A value of zero or less, means use the default timeout.
timeout
)

Implements abstract sun.net.ftp.FtpClient.setReadTimeout.

Sets the timeout value to use when reading from the server,

public FtpClient
setRestartOffset(long
the offset in the remote file at which to start the next transfer. This must be a value greater than or equal to zero.
offset
)

Implements abstract sun.net.ftp.FtpClient.setRestartOffset.

Sets the restart offset to the specified value.

public FtpClient

Returns:

This FtpClient
setType
(FtpClient.TransferType
the FtpTransferType to use.
type
)

Implements abstract sun.net.ftp.FtpClient.setType.

Changes the transfer type (binary, ascii, ebcdic) and issue the proper command (e.g. TYPE A) to the server.

public FtpClient

Returns:

true if the command was successful.
siteCmd
(String
the command to be sent.
cmd
)

Implements abstract sun.net.ftp.FtpClient.siteCmd.

Sends the SITE command to the server.

public FtpClient

Returns:

true if the operation was successful.
startSecureSession
()

Implements abstract sun.net.ftp.FtpClient.startSecureSession.

Attempts to switch to a secure, encrypted connection.

public FtpClient

Returns:

true if the operation was successful.
structureMount
(String
a String containing the name of the structure to mount.
struct
)

Implements abstract sun.net.ftp.FtpClient.structureMount.

Sends the "Structure Mount" (SMNT) command to the server.

private void
tryConnect(InetSocketAddress
the InetSocketAddress to connect to.
dest
,
int timeout)

Connects to the specified destination.

private void
tryLogin(String user, char[] password)

public FtpClient

Returns:

true if authentication was successful.
useKerberos
()

Implements abstract sun.net.ftp.FtpClient.useKerberos.

Attempts to use Kerberos GSSAPI as an authentication mechanism with the ftp server.

private InetSocketAddress
validatePasvAddress(int port, String s, InetAddress address)

Returns an InetSocketAddress, based on value of acceptPasvAddressVal and other conditions such as the server address returned by pasv is not a hostname, is a socks proxy, or the loopback.

Inherited from sun.net.ftp.FtpClient:
createcreatedefaultPortputFileputFileStreamsetAsciiTypesetBinaryType