29
30 package sun.net.www.protocol.ftp;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.io.BufferedInputStream;
36 import java.io.FilterInputStream;
37 import java.io.FilterOutputStream;
38 import java.io.FileNotFoundException;
39 import java.net.URL;
40 import java.net.SocketPermission;
41 import java.net.UnknownHostException;
42 import java.net.InetSocketAddress;
43 import java.net.URI;
44 import java.net.Proxy;
45 import java.net.ProxySelector;
46 import java.util.StringTokenizer;
47 import java.util.Iterator;
48 import java.security.Permission;
49 import sun.net.www.MessageHeader;
50 import sun.net.www.MeteredStream;
51 import sun.net.www.URLConnection;
52 import sun.net.www.protocol.http.HttpURLConnection;
53 import sun.net.ftp.FtpClient;
54 import sun.net.ftp.FtpProtocolException;
55 import sun.net.ProgressSource;
56 import sun.net.ProgressMonitor;
57 import sun.net.www.ParseUtil;
58 import sun.security.action.GetPropertyAction;
59
60
61 /**
62 * This class Opens an FTP input (or output) stream given a URL.
63 * It works as a one shot FTP transfer :
64 * <UL>
65 * <LI>Login</LI>
66 * <LI>Get (or Put) the file</LI>
67 * <LI>Disconnect</LI>
68 * </UL>
85
86 InputStream is = null;
87 OutputStream os = null;
88
89 FtpClient ftp = null;
90 Permission permission;
91
92 String password;
93 String user;
94
95 String host;
96 String pathname;
97 String filename;
98 String fullpath;
99 int port;
100 static final int NONE = 0;
101 static final int ASCII = 1;
102 static final int BIN = 2;
103 static final int DIR = 3;
104 int type = NONE;
105 /* Redefine timeouts from java.net.URLConnection as we nee -1 to mean
106 * not set. This is to ensure backward compatibility.
107 */
108 private int connectTimeout = -1;
109 private int readTimeout = -1;
110
111 /**
112 * For FTP URLs we need to have a special InputStream because we
113 * need to close 2 sockets after we're done with it :
114 * - The Data socket (for the file).
115 * - The command socket (FtpClient).
116 * Since that's the only class that needs to see that, it is an inner class.
117 */
118 protected class FtpInputStream extends FilterInputStream {
119 FtpClient ftp;
120 FtpInputStream(FtpClient cl, InputStream fd) {
121 super(new BufferedInputStream(fd));
122 ftp = cl;
123 }
124
125 @Override
126 public void close() throws IOException {
127 super.close();
128 if (ftp != null) {
129 ftp.close();
|
29
30 package sun.net.www.protocol.ftp;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.io.BufferedInputStream;
36 import java.io.FilterInputStream;
37 import java.io.FilterOutputStream;
38 import java.io.FileNotFoundException;
39 import java.net.URL;
40 import java.net.SocketPermission;
41 import java.net.UnknownHostException;
42 import java.net.InetSocketAddress;
43 import java.net.URI;
44 import java.net.Proxy;
45 import java.net.ProxySelector;
46 import java.util.StringTokenizer;
47 import java.util.Iterator;
48 import java.security.Permission;
49 import sun.net.NetworkClient;
50 import sun.net.www.MessageHeader;
51 import sun.net.www.MeteredStream;
52 import sun.net.www.URLConnection;
53 import sun.net.www.protocol.http.HttpURLConnection;
54 import sun.net.ftp.FtpClient;
55 import sun.net.ftp.FtpProtocolException;
56 import sun.net.ProgressSource;
57 import sun.net.ProgressMonitor;
58 import sun.net.www.ParseUtil;
59 import sun.security.action.GetPropertyAction;
60
61
62 /**
63 * This class Opens an FTP input (or output) stream given a URL.
64 * It works as a one shot FTP transfer :
65 * <UL>
66 * <LI>Login</LI>
67 * <LI>Get (or Put) the file</LI>
68 * <LI>Disconnect</LI>
69 * </UL>
86
87 InputStream is = null;
88 OutputStream os = null;
89
90 FtpClient ftp = null;
91 Permission permission;
92
93 String password;
94 String user;
95
96 String host;
97 String pathname;
98 String filename;
99 String fullpath;
100 int port;
101 static final int NONE = 0;
102 static final int ASCII = 1;
103 static final int BIN = 2;
104 static final int DIR = 3;
105 int type = NONE;
106 /* Redefine timeouts from java.net.URLConnection as we need -1 to mean
107 * not set. This is to ensure backward compatibility.
108 */
109 private int connectTimeout = NetworkClient.DEFAULT_CONNECT_TIMEOUT;;
110 private int readTimeout = NetworkClient.DEFAULT_READ_TIMEOUT;;
111
112 /**
113 * For FTP URLs we need to have a special InputStream because we
114 * need to close 2 sockets after we're done with it :
115 * - The Data socket (for the file).
116 * - The command socket (FtpClient).
117 * Since that's the only class that needs to see that, it is an inner class.
118 */
119 protected class FtpInputStream extends FilterInputStream {
120 FtpClient ftp;
121 FtpInputStream(FtpClient cl, InputStream fd) {
122 super(new BufferedInputStream(fd));
123 ftp = cl;
124 }
125
126 @Override
127 public void close() throws IOException {
128 super.close();
129 if (ftp != null) {
130 ftp.close();
|