jdk/test/sun/net/ftp/FtpURL.java
author chegar
Wed, 21 Jul 2010 13:29:26 +0100
changeset 6115 7c523cf2bc8a
parent 5506 202f599c92aa
child 7668 d4a77089c587
permissions -rw-r--r--
6969395: TEST_BUG: Tests in java/net sun/net problems Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @bug 4398880
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @summary FTP URL processing modified to conform to RFC 1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class FtpURL {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
     * A class that simulates, on a separate, an FTP server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private class FtpServer extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        private ServerSocket    server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        private int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        private boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        private boolean portEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        private boolean pasvEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        private String username;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        private String password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        private String cwd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        private String filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        private boolean list = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * This Inner class will handle ONE client at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * That's where 99% of the protocol handling is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        private class FtpServerHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            BufferedReader in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            PrintWriter out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            Socket client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            private final int ERROR = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            private final int USER = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            private final int PASS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            private final int CWD = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            private final int CDUP = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            private final int PWD = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            private final int TYPE = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            private final int NOOP = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            private final int RETR = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            private final int PASV = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            private final int PORT = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            private final int LIST = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            private final int REIN = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            private final int QUIT = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            private final int STOR = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            private final int NLST = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            private final int RNFR = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            private final int RNTO = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            String[] cmds = { "USER", "PASS", "CWD", "CDUP", "PWD", "TYPE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                              "NOOP", "RETR", "PASV", "PORT", "LIST", "REIN",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                              "QUIT", "STOR", "NLST", "RNFR", "RNTO" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            private String arg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            private ServerSocket pasv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            private int data_port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            private InetAddress data_addr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
             * Parses a line to match it with one of the supported FTP commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
             * Returns the command number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            private int parseCmd(String cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                if (cmd == null || cmd.length() < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    return ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                int blank = cmd.indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                if (blank < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    blank = cmd.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                if (blank < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    return ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                String s = cmd.substring(0, blank);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                if (cmd.length() > blank+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    arg = cmd.substring(blank+1, cmd.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    arg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                for (int i = 0; i < cmds.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    if (s.equalsIgnoreCase(cmds[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        return i+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            public FtpServerHandler(Socket cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                client = cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            protected boolean isPasvSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                if (pasv != null && !pasvEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        pasv.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    pasv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (pasvEnabled && pasv != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
             * Open the data socket with the client. This can be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
             * result of a "PASV" or "PORT" command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            protected OutputStream getOutDataStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    if (isPasvSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        Socket s = pasv.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        return s.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    if (data_addr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        Socket s = new Socket(data_addr, data_port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        data_addr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        data_port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        return s.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            protected InputStream getInDataStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    if (isPasvSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        Socket s = pasv.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        return s.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    if (data_addr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        Socket s = new Socket(data_addr, data_port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        data_addr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        data_port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                        return s.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
             * Handles the protocol exchange with the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                String str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                int res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                boolean logged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                boolean waitpass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    out = new PrintWriter(client.getOutputStream(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    out.println("220 tatooine FTP server (SunOS 5.8) ready.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                synchronized (FtpServer.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                  while (!done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        str = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        res = parseCmd(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        if ((res > PASS && res != QUIT) && !logged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                            out.println("530 Not logged in.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        switch (res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        case ERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                            out.println("500 '" + str + "': command not understood.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        case USER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                            if (!logged && !waitpass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                username = str.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                password = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                cwd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                if ("user2".equals(username)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                    out.println("230 Guest login ok, access restrictions apply.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                    logged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                    out.println("331 Password required for " + arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                    waitpass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                out.println("503 Bad sequence of commands.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        case PASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                            if (!logged && waitpass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                out.println("230 Guest login ok, access restrictions apply.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                password = str.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                logged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                waitpass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                out.println("503 Bad sequence of commands.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        case QUIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                            out.println("221 Goodbye.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                            out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                            if (pasv != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                pasv.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        case TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                            out.println("200 Type set to " + arg + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                            type = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        case CWD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                            out.println("250 CWD command successful.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                            if (cwd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                cwd = str.substring(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                cwd = cwd + "/" + str.substring(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        case CDUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            out.println("250 CWD command successful.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        case PWD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            out.println("257 \"" + cwd + "\" is current directory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        case PASV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            if (!pasvEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                out.println("500 PASV is disabled, use PORT instead.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                if (pasv == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                    pasv = new ServerSocket(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                int port = pasv.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                out.println("227 Entering Passive Mode (127,0,0,1," +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                            (port >> 8) + "," + (port & 0xff) +")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            } catch (IOException ssex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                out.println("425 Can't build data connection: Connection refused.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        case PORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                            if (!portEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                out.println("500 PORT is disabled, use PASV instead");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                            StringBuffer host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            int i=0, j=4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            while (j>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                i = arg.indexOf(',', i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                if (i < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                j--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                            if (j != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                out.println("500 '" + arg + "': command not understood.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                host = new StringBuffer(arg.substring(0,i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                for (j=0; j < host.length(); j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                    if (host.charAt(j) == ',')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                        host.setCharAt(j, '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                String ports = arg.substring(i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                i = ports.indexOf(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                data_port = Integer.parseInt(ports.substring(0,i)) << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                data_port += (Integer.parseInt(ports.substring(i+1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                data_addr = InetAddress.getByName(host.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                out.println("200 Command okay.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                            } catch (Exception ex3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                data_port = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                data_addr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                out.println("500 '" + arg + "': command not understood.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        case RETR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                filename = str.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                OutputStream dout = getOutDataStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                if (dout != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                    out.println("200 Command okay.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                    PrintWriter pout = new PrintWriter(new BufferedOutputStream(dout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                    pout.println("Hello World!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                    pout.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                    pout.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                    list = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                    out.println("425 Can't build data connection: Connection refused.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        case NLST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            filename = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        case LIST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                OutputStream dout = getOutDataStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                if (dout != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                    out.println("200 Command okay.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                    PrintWriter pout = new PrintWriter(new BufferedOutputStream(dout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                    pout.println("total 130");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                    pout.println("drwxrwxrwt   7 sys      sys          577 May 12 03:30 .");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                    pout.println("drwxr-xr-x  39 root     root        1024 Mar 27 12:55 ..");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                    pout.println("drwxrwxr-x   2 root     root         176 Apr 10 12:02 .X11-pipe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                    pout.println("drwxrwxr-x   2 root     root         176 Apr 10 12:02 .X11-unix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                    pout.println("drwxrwxrwx   2 root     root         179 Mar 30 15:09 .pcmcia");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                    pout.println("drwxrwxrwx   2 jladen   staff        117 Mar 30 18:18 .removable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                    pout.println("drwxrwxrwt   2 root     root         327 Mar 30 15:08 .rpc_door");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                    pout.println("-rw-r--r--   1 root     other         21 May  5 16:59 hello2.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                    pout.println("-rw-rw-r--   1 root     sys         5968 Mar 30 15:08 ps_data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                    pout.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                    pout.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                    list = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                        FtpServer.this.wait ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                    } catch (Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                    out.println("425 Can't build data connection: Connection refused.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        case STOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                InputStream is = getInDataStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                if (is != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                    out.println("200 Command okay.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                    BufferedInputStream din = new BufferedInputStream(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                    int val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                        val = din.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                    } while (val != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                    din.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                    out.println("425 Can't build data connection: Connection refused.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        ioe.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        } catch (Exception ex2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public FtpServer(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
              server = new ServerSocket(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        public FtpServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            this(21);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        public int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (server != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                return server.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * A way to tell the server that it can stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        synchronized public void terminate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        synchronized public void setPortEnabled(boolean ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            portEnabled = ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        synchronized public void setPasvEnabled(boolean ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            pasvEnabled = ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        String getUsername() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return username;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String getPassword() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        String pwd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return cwd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        String getFilename() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        synchronized boolean getList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            notify ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * All we got to do here is create a ServerSocket and wait for connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * When a connection happens, we just have to create a thread that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         * handle it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                Socket client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                for (int i=0; i<2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    client = server.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    (new FtpServerHandler(client)).run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            } catch(Exception e) {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   442
            } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   443
                try { server.close(); } catch (IOException unused) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        FtpURL test = new FtpURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public FtpURL() throws Exception {
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   452
        FtpServer server = new FtpServer(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        BufferedReader in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            server.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            int port = server.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            // Now let's check the URL handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            URL url = new URL("ftp://user:password@localhost:" + port + "/%2Fetc/motd;type=a");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            URLConnection con = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            in = new BufferedReader(new InputStreamReader(con.getInputStream()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                s = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            } while (s != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (!("user".equals(server.getUsername())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                throw new RuntimeException("Inccorect username received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (!("password".equals(server.getPassword())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                throw new RuntimeException("Inccorect password received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            if (!("/etc".equals(server.pwd())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                throw new RuntimeException("Inccorect directory received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (!("motd".equals(server.getFilename())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                throw new RuntimeException("Inccorect username received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            if (!("A".equals(server.getType())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                throw new RuntimeException("Incorrect type received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // We're done!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            // Second URL test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            port = server.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            // Now let's check the URL handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            url = new URL("ftp://user2:@localhost:" + port + "/%2Fusr/bin;type=d");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            con = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            in = new BufferedReader(new InputStreamReader(con.getInputStream()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                s = in.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            } while (s != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if (!server.getList())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                throw new RuntimeException(";type=d didn't generate a NLST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (server.getPassword() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                throw new RuntimeException("password should be null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (! "bin".equals(server.getFilename()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                throw new RuntimeException("Incorrect filename received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (! "/usr".equals(server.pwd()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                throw new RuntimeException("Incorrect pwd received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            // We're done!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            throw new RuntimeException("FTP support error: " + e.getMessage());
6115
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   504
        } finally {
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   505
            try { in.close(); } catch (IOException unused) {}
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   506
            server.terminate();
7c523cf2bc8a 6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents: 5506
diff changeset
   507
            server.server.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
}