Top Description Inners Fields Constructors Methods
sun.net.www.protocol.ftp

public Class FtpURLConnection

extends URLConnection
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, .BufferedInputStream, .FilterInputStream, .FilterOutputStream, .FileNotFoundException, java.net.MalformedURLException, .URL, .SocketPermission, .UnknownHostException, .InetSocketAddress, .URI, .Proxy, .ProxySelector, java.util.List, .StringTokenizer, .Properties, java.security.Permission, sun.net.NetworkClient, sun.net.util.IPAddressUtil, sun.net.www.MessageHeader, .MeteredStream, .URLConnection, .ParseUtil, sun.net.www.protocol.http.HttpURLConnection, sun.net.ftp.FtpClient, .FtpProtocolException, sun.security.action.GetPropertyAction

This class Opens an FTP input (or output) stream given a URL. It works as a one shot FTP transfer : You should not have to use it directly in most cases because all will be handled in a abstract layer. Here is an example of how to use the class:
URL url = new URL("ftp://ftp.sun.com/pub/test.txt");
UrlConnection con = url.openConnection();
InputStream is = con.getInputStream();
...
is.close();
See Also
sun.net.ftp.FtpClient

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
FtpURLConnection.FtpInputStream

For FTP URLs we need to have a special InputStream because we need to close 2 sockets after we're done with it : - The Data socket (for the file).

protected static class
FtpURLConnection.FtpOutputStream

For FTP URLs we need to have a special OutputStream because we need to close 2 sockets after we're done with it : - The Data socket (for the file).

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
private int
pack-priv static final int
pack-priv String
pack-priv FtpClient
pack-priv String
pack-priv String
pack-priv HttpURLConnection
private final Proxy
pack-priv InputStream
pack-priv static final int
pack-priv OutputStream
pack-priv String
pack-priv String
pack-priv Permission
pack-priv int
private int
pack-priv int
pack-priv String
Inherited from sun.net.www.URLConnection:
properties

Constructor Summary

AccessConstructor and Description
public
FtpURLConnection(URL
The URL to retrieve or store.
url
)

Creates an FtpURLConnection from a URL.

pack-priv
FtpURLConnection(URL url, Proxy p)

Same as FtpURLconnection(URL) with a per connection proxy specified

Method Summary

Modifier and TypeMethod and Description
private void
cd(String path)

private static URL
public synchronized void
connect()

Implements abstract java.net.URLConnection.connect.

Connects to the FTP server and logs in.

private void
public int
getConnectTimeout()

Overrides java.net.URLConnection.getConnectTimeout.

Returns setting for connect timeout.

public InputStream

Returns:

the InputStream to the connection.
getInputStream
()

Overrides java.net.URLConnection.getInputStream.

Get the InputStream to retrieve the remote file.

public OutputStream

Returns:

the OutputStream to the connection.
getOutputStream
()

Overrides java.net.URLConnection.getOutputStream.

Get the OutputStream to store the remote file.

public Permission

Returns:

The Permission object.
getPermission
()

Overrides java.net.URLConnection.getPermission.

Gets the Permission associated with the host and port.

public int
getReadTimeout()

Overrides java.net.URLConnection.getReadTimeout.

Returns setting for read timeout.

public String

Returns:

the value of the named general request property for this connection.
getRequestProperty
(String
the keyword by which the request is known (e.g., "accept").
key
)

Overrides sun.net.www.URLConnection.getRequestProperty.

Returns the value of the named general request property for this connection.

pack-priv String
public void
setConnectTimeout(int
an int that specifies the connect timeout value in milliseconds
timeout
)

Overrides java.net.URLConnection.setConnectTimeout.

Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.

public void
setReadTimeout(int
an int that specifies the timeout value to be used in milliseconds
timeout
)

Overrides java.net.URLConnection.setReadTimeout.

Sets the read timeout to a specified timeout, in milliseconds.

public void
setRequestProperty(String
the keyword by which the request is known (e.g., "accept").
key
,
String
the value associated with it.
value
)

Overrides sun.net.www.URLConnection.setRequestProperty.

Sets the general request property.

private void
Inherited from sun.net.www.URLConnection:
addRequestPropertycanCacheclosegetContentLengthgetContentTypegetHeaderFieldgetHeaderFieldgetHeaderFieldKeygetHeaderFieldsgetPropertiesgetRequestPropertiesisProxiedHostsetContentLengthsetContentTypesetPropertiessetProxiedHost

Field Detail

ASCIIback to summary
pack-priv static final int ASCII
BINback to summary
pack-priv static final int BIN
connectTimeoutback to summary
private int connectTimeout

Hides java.net.URLConnection.connectTimeout.

DIRback to summary
pack-priv static final int DIR
filenameback to summary
pack-priv String filename
ftpback to summary
pack-priv FtpClient ftp
fullpathback to summary
pack-priv String fullpath
hostback to summary
pack-priv String host
httpback to summary
pack-priv HttpURLConnection http
instProxyback to summary
private final Proxy instProxy
isback to summary
pack-priv InputStream is
NONEback to summary
pack-priv static final int NONE
osback to summary
pack-priv OutputStream os
passwordback to summary
pack-priv String password
pathnameback to summary
pack-priv String pathname
permissionback to summary
pack-priv Permission permission
portback to summary
pack-priv int port
readTimeoutback to summary
private int readTimeout

Hides java.net.URLConnection.readTimeout.

typeback to summary
pack-priv int type
userback to summary
pack-priv String user

Constructor Detail

FtpURLConnectionback to summary
public FtpURLConnection(URL url) throws MalformedURLException

Creates an FtpURLConnection from a URL.

Parameters
url:URL

The URL to retrieve or store.

FtpURLConnectionback to summary
pack-priv FtpURLConnection(URL url, Proxy p) throws MalformedURLException

Same as FtpURLconnection(URL) with a per connection proxy specified

Method Detail

cdback to summary
private void cd(String path) throws FtpProtocolException, IOException
checkURLback to summary
private static URL checkURL(URL u) throws MalformedURLException
connectback to summary
public synchronized void connect() throws IOException

Implements abstract java.net.URLConnection.connect.

Connects to the FTP server and logs in.

Exceptions
IOException:

Doc from java.net.URLConnection.connect.

if an I/O error occurs while opening the connection.

FtpLoginException:
if the login is unsuccessful
FtpProtocolException:
if an error occurs
UnknownHostException:
if trying to connect to an unknown host
decodePathback to summary
private void decodePath(String path)
getConnectTimeoutback to summary
public int getConnectTimeout()

Overrides java.net.URLConnection.getConnectTimeout.

Doc from java.net.URLConnection.getConnectTimeout.

Returns setting for connect timeout.

0 return implies that the option is disabled (i.e., timeout of infinity).

Returns:int

an int that indicates the connect timeout value in milliseconds

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides java.net.URLConnection.getInputStream.

Get the InputStream to retrieve the remote file. It will issue the "get" (or "dir") command to the ftp server.

Returns:InputStream

the InputStream to the connection.

Annotations
@Override
Exceptions
IOException:
if already opened for output
FtpProtocolException:
if errors occur during the transfer.
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Overrides java.net.URLConnection.getOutputStream.

Get the OutputStream to store the remote file. It will issue the "put" command to the ftp server.

Returns:OutputStream

the OutputStream to the connection.

Annotations
@Override
Exceptions
IOException:
if already opened for input or the URL points to a directory
FtpProtocolException:
if errors occur during the transfer.
getPermissionback to summary
public Permission getPermission()

Overrides java.net.URLConnection.getPermission.

Gets the Permission associated with the host and port.

Returns:Permission

The Permission object.

Annotations
@Override
getReadTimeoutback to summary
public int getReadTimeout()

Overrides java.net.URLConnection.getReadTimeout.

Doc from java.net.URLConnection.getReadTimeout.

Returns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).

Returns:int

an int that indicates the read timeout value in milliseconds

Annotations
@Override
getRequestPropertyback to summary
public String getRequestProperty(String key)

Overrides sun.net.www.URLConnection.getRequestProperty.

Returns the value of the named general request property for this connection.

Parameters
key:String

the keyword by which the request is known (e.g., "accept").

Returns:String

the value of the named general request property for this connection.

Annotations
@Override
Exceptions
IllegalStateException:
if already connected
See Also
setRequestProperty(java.lang.String, java.lang.String)
guessContentTypeFromFilenameback to summary
pack-priv String guessContentTypeFromFilename(String fname)
setConnectTimeoutback to summary
public void setConnectTimeout(int timeout)

Overrides java.net.URLConnection.setConnectTimeout.

Doc from java.net.URLConnection.setConnectTimeout.

Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.

Some non-standard implementation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().

Parameters
timeout:int

an int that specifies the connect timeout value in milliseconds

Annotations
@Override
setReadTimeoutback to summary
public void setReadTimeout(int timeout)

Overrides java.net.URLConnection.setReadTimeout.

Doc from java.net.URLConnection.setReadTimeout.

Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.

Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().

Parameters
timeout:int

an int that specifies the timeout value to be used in milliseconds

Annotations
@Override
setRequestPropertyback to summary
public void setRequestProperty(String key, String value)

Overrides sun.net.www.URLConnection.setRequestProperty.

Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

Parameters
key:String

the keyword by which the request is known (e.g., "accept").

value:String

the value associated with it.

Annotations
@Override
Exceptions
IllegalStateException:
if already connected
See Also
getRequestProperty(java.lang.String)
setTimeoutsback to summary
private void setTimeouts()
sun.net.www.protocol.ftp back to summary

protected Class FtpURLConnection.FtpInputStream

extends FilterInputStream
Class Inheritance

For FTP URLs we need to have a special InputStream because we need to close 2 sockets after we're done with it : - The Data socket (for the file). - The command socket (FtpClient). Since that's the only class that needs to see that, it is an inner class.

Field Summary

Modifier and TypeField and Description
pack-priv FtpClient
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

Inherited from java.io.FilterInputStream:
availablemarkmarkSupportedreadreadreadresetskip

Field Detail

ftpback to summary
pack-priv FtpClient ftp

Constructor Detail

FtpInputStreamback to summary
pack-priv FtpInputStream(FtpClient cl, InputStream fd)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterInputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
sun.net.www.protocol.ftp back to summary

protected Class FtpURLConnection.FtpOutputStream

extends FilterOutputStream
Class Inheritance

For FTP URLs we need to have a special OutputStream because we need to close 2 sockets after we're done with it : - The Data socket (for the file). - The command socket (FtpClient). Since that's the only class that needs to see that, it is an inner class.

Field Summary

Modifier and TypeField and Description
pack-priv FtpClient
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with the stream.

Inherited from java.io.FilterOutputStream:
flushwritewritewrite

Field Detail

ftpback to summary
pack-priv FtpClient ftp

Constructor Detail

FtpOutputStreamback to summary
pack-priv FtpOutputStream(FtpClient cl, OutputStream fd)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterOutputStream.close.

Closes this output stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.