15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.net.ftp.impl;
26
27 import java.net.*;
28 import java.io.*;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.text.DateFormat;
32 import java.text.ParseException;
33 import java.text.SimpleDateFormat;
34 import java.util.ArrayList;
35 import java.util.Calendar;
36 import java.util.Date;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.TimeZone;
40 import java.util.Vector;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43 import javax.net.ssl.SSLSocket;
44 import javax.net.ssl.SSLSocketFactory;
45 import sun.misc.BASE64Decoder;
46 import sun.misc.BASE64Encoder;
47 import sun.net.ftp.*;
48 import sun.util.logging.PlatformLogger;
49
50
51 public class FtpClient extends sun.net.ftp.FtpClient {
52
53 private static int defaultSoTimeout;
54 private static int defaultConnectTimeout;
55 private static final PlatformLogger logger =
56 PlatformLogger.getLogger("sun.net.ftp.FtpClient");
57 private Proxy proxy;
58 private Socket server;
59 private PrintStream out;
60 private InputStream in;
61 private int readTimeout = -1;
62 private int connectTimeout = -1;
63
64 /* Name of encoding to use for output */
65 private static String encoding = "ISO8859_1";
66 /** remember the ftp server name because we may need it */
1882 s = openDataConnection(path == null ? "MLSD" : "MLSD " + path);
1883 } catch (sun.net.ftp.FtpProtocolException FtpException) {
1884 // The server doesn't understand new MLSD command, ignore and fall
1885 // back to LIST
1886 }
1887
1888 if (s != null) {
1889 sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
1890 return new FtpFileIterator(mlsxParser, sin);
1891 } else {
1892 s = openDataConnection(path == null ? "LIST" : "LIST " + path);
1893 if (s != null) {
1894 sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
1895 return new FtpFileIterator(parser, sin);
1896 }
1897 }
1898 return null;
1899 }
1900
1901 private boolean sendSecurityData(byte[] buf) throws IOException {
1902 BASE64Encoder encoder = new BASE64Encoder();
1903 String s = encoder.encode(buf);
1904 return issueCommand("ADAT " + s);
1905 }
1906
1907 private byte[] getSecurityData() {
1908 String s = getLastResponseString();
1909 if (s.substring(4, 9).equalsIgnoreCase("ADAT=")) {
1910 BASE64Decoder decoder = new BASE64Decoder();
1911 try {
1912 // Need to get rid of the leading '315 ADAT='
1913 // and the trailing newline
1914 return decoder.decodeBuffer(s.substring(9, s.length() - 1));
1915 } catch (IOException e) {
1916 //
1917 }
1918 }
1919 return null;
1920 }
1921
1922 /**
1923 * Attempts to use Kerberos GSSAPI as an authentication mechanism with the
1924 * ftp server. This will issue an <code>AUTH GSSAPI</code> command, and if
1925 * it is accepted by the server, will followup with <code>ADAT</code>
1926 * command to exchange the various tokens until authentification is
1927 * successful. This conforms to Appendix I of RFC 2228.
1928 *
1929 * @return <code>true</code> if authentication was successful.
1930 * @throws IOException if an error occurs during the transmission.
1931 */
1932 public sun.net.ftp.FtpClient useKerberos() throws sun.net.ftp.FtpProtocolException, IOException {
1933 /*
1934 * Comment out for the moment since it's not in use and would create
1935 * needless cross-package links.
1936 *
1937 issueCommandCheck("AUTH GSSAPI");
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.net.ftp.impl;
26
27 import java.net.*;
28 import java.io.*;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.text.DateFormat;
32 import java.text.ParseException;
33 import java.text.SimpleDateFormat;
34 import java.util.ArrayList;
35 import java.util.Base64;
36 import java.util.Calendar;
37 import java.util.Date;
38 import java.util.Iterator;
39 import java.util.List;
40 import java.util.TimeZone;
41 import java.util.Vector;
42 import java.util.regex.Matcher;
43 import java.util.regex.Pattern;
44 import javax.net.ssl.SSLSocket;
45 import javax.net.ssl.SSLSocketFactory;
46 import sun.net.ftp.*;
47 import sun.util.logging.PlatformLogger;
48
49
50 public class FtpClient extends sun.net.ftp.FtpClient {
51
52 private static int defaultSoTimeout;
53 private static int defaultConnectTimeout;
54 private static final PlatformLogger logger =
55 PlatformLogger.getLogger("sun.net.ftp.FtpClient");
56 private Proxy proxy;
57 private Socket server;
58 private PrintStream out;
59 private InputStream in;
60 private int readTimeout = -1;
61 private int connectTimeout = -1;
62
63 /* Name of encoding to use for output */
64 private static String encoding = "ISO8859_1";
65 /** remember the ftp server name because we may need it */
1881 s = openDataConnection(path == null ? "MLSD" : "MLSD " + path);
1882 } catch (sun.net.ftp.FtpProtocolException FtpException) {
1883 // The server doesn't understand new MLSD command, ignore and fall
1884 // back to LIST
1885 }
1886
1887 if (s != null) {
1888 sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
1889 return new FtpFileIterator(mlsxParser, sin);
1890 } else {
1891 s = openDataConnection(path == null ? "LIST" : "LIST " + path);
1892 if (s != null) {
1893 sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
1894 return new FtpFileIterator(parser, sin);
1895 }
1896 }
1897 return null;
1898 }
1899
1900 private boolean sendSecurityData(byte[] buf) throws IOException {
1901 String s = Base64.getMimeEncoder().encodeToString(buf);
1902 return issueCommand("ADAT " + s);
1903 }
1904
1905 private byte[] getSecurityData() {
1906 String s = getLastResponseString();
1907 if (s.substring(4, 9).equalsIgnoreCase("ADAT=")) {
1908 // Need to get rid of the leading '315 ADAT='
1909 // and the trailing newline
1910 return Base64.getMimeDecoder().decode(s.substring(9, s.length() - 1));
1911 }
1912 return null;
1913 }
1914
1915 /**
1916 * Attempts to use Kerberos GSSAPI as an authentication mechanism with the
1917 * ftp server. This will issue an <code>AUTH GSSAPI</code> command, and if
1918 * it is accepted by the server, will followup with <code>ADAT</code>
1919 * command to exchange the various tokens until authentification is
1920 * successful. This conforms to Appendix I of RFC 2228.
1921 *
1922 * @return <code>true</code> if authentication was successful.
1923 * @throws IOException if an error occurs during the transmission.
1924 */
1925 public sun.net.ftp.FtpClient useKerberos() throws sun.net.ftp.FtpProtocolException, IOException {
1926 /*
1927 * Comment out for the moment since it's not in use and would create
1928 * needless cross-package links.
1929 *
1930 issueCommandCheck("AUTH GSSAPI");
|