/[classpath]/inetlib/source/gnu/inet/ftp/FTPConnection.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/ftp/FTPConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by dog, Sun Oct 19 16:16:49 2003 UTC revision 1.3 by dog, Mon Oct 20 17:20:53 2003 UTC
# Line 121  public class FTPConnection Line 121  public class FTPConnection
121    private static final String US_ASCII = "US-ASCII";    private static final String US_ASCII = "US-ASCII";
122    private static final byte[] CRLF = { 0x0d, 0x0a };    private static final byte[] CRLF = { 0x0d, 0x0a };
123    
124          /**    /**
125           * The socket used to communicate with the server.           * The socket used to communicate with the server.
126           */           */
127    protected Socket socket;    protected Socket socket;
128    
129          /**    /**
130           * The socket input stream.           * The socket input stream.
131           */           */
132    protected LineInputStream in;    protected LineInputStream in;
133    
134          /**    /**
135           * The socket output stream.           * The socket output stream.
136           */           */
137    protected OutputStream out;    protected OutputStream out;
138    
139          /**    /**
140           * If true, print debugging information.           * If true, print debugging information.
141           */           */
142    protected boolean debug;    protected boolean debug;
143    
144          /**    /**
145           * The current data transfer process in use by this connection.           * The current data transfer process in use by this connection.
146           */           */
147    protected DTP dtp;    protected DTP dtp;
148    
149          /**    /**
150           * The current representation type.           * The current representation type.
151           */           */
152    protected int representationType = TYPE_ASCII;    protected int representationType = TYPE_ASCII;
153    
154          /**    /**
155           * The current file structure type.           * The current file structure type.
156           */           */
157    protected int fileStructure = STRUCTURE_FILE;    protected int fileStructure = STRUCTURE_FILE;
158    
159          /**    /**
160           * The current transfer mode.           * The current transfer mode.
161           */           */
162    protected int transferMode = MODE_STREAM;    protected int transferMode = MODE_STREAM;
163    
164          /**    /**
165           * If true, use passive mode.           * If true, use passive mode.
166           */           */
167    protected boolean passive = false;    protected boolean passive = false;
# Line 226  public class FTPConnection Line 226  public class FTPConnection
226      }      }
227    }    }
228    
229          /**    /**
230           * Authenticate using the specified username and password.           * Authenticate using the specified username and password.
231           * If the username suffices for the server, the password will not be used           * If the username suffices for the server, the password will not be used
232           * and may be null.           * and may be null.
# Line 243  public class FTPConnection Line 243  public class FTPConnection
243      FTPResponse response = getResponse();      FTPResponse response = getResponse();
244      switch (response.getCode())      switch (response.getCode())
245      {      {
246      case 230:                  // User logged in        case 230:                  // User logged in
247        return true;          return true;
248        case 331:                 // User name okay, need password        case 331:                 // User name okay, need password
249        break;          break;
250        case 332:                 // Need account for login        case 332:                 // Need account for login
251        case 530:                 // No such user        case 530:                 // No such user
252        return false;          return false;
253        default:throw new FTPException(response);        default:throw new FTPException(response);
254      }      }
255      cmd = new StringBuffer(PASS).append(' ').append(password).toString();      cmd = new StringBuffer(PASS).append(' ').append(password).toString();
# Line 257  public class FTPConnection Line 257  public class FTPConnection
257      response = getResponse();      response = getResponse();
258      switch (response.getCode())      switch (response.getCode())
259      {      {
260      case 230:                  // User logged in        case 230:                  // User logged in
261      case 202:                  // Superfluous        case 202:                  // Superfluous
262        return true;          return true;
263      case 332:                  // Need account for login        case 332:                  // Need account for login
264      case 530:                  // Bad password        case 530:                  // Bad password
265        return false;          return false;
266      default:        default:
267        throw new FTPException(response);          throw new FTPException(response);
268      }      }
269    }    }
270    
271          /**    /**
272           * Changes directory to the specified path.           * Changes directory to the specified path.
273           * @param path an absolute or relative pathname           * @param path an absolute or relative pathname
274           * @return true on success, false if the specified path does not exist           * @return true on success, false if the specified path does not exist
# Line 276  public class FTPConnection Line 276  public class FTPConnection
276    public boolean changeWorkingDirectory(String path) throws IOException    public boolean changeWorkingDirectory(String path) throws IOException
277    {    {
278      String cmd = new StringBuffer(CWD).append(' ').append(path).toString();      String cmd = new StringBuffer(CWD).append(' ').append(path).toString();
279        send(cmd);      send(cmd);
280      FTPResponse response = getResponse();      FTPResponse response = getResponse();
281      switch (response.getCode())      switch (response.getCode())
282      {      {
283      case 250:        case 250:
284        return true;          return true;
285        case 550:return false;        case 550:return false;
286        default:throw new FTPException(response);        default:throw new FTPException(response);
287      }      }
288    }    }
289    
290          /**    /**
291           * Changes directory to the parent of the current working directory.           * Changes directory to the parent of the current working directory.
292           * @return true on success, false otherwise           * @return true on success, false otherwise
293           */           */
# Line 297  public class FTPConnection Line 297  public class FTPConnection
297      FTPResponse response = getResponse();      FTPResponse response = getResponse();
298      switch (response.getCode())      switch (response.getCode())
299      {      {
300      case 250:        case 250:
301        return true;          return true;
302        case 550:return false;        case 550:return false;
303        default:throw new FTPException(response);        default:throw new FTPException(response);
304      }      }
305    }    }
306    
307          /**    /**
308           * Terminates an authenticated login.           * Terminates an authenticated login.
309           * If file transfer is in progress, it remains active for result response           * If file transfer is in progress, it remains active for result response
310           * only.           * only.
# Line 327  public class FTPConnection Line 327  public class FTPConnection
327      }      }
328    }    }
329    
330          /**    /**
331           * Terminates the control connection.           * Terminates the control connection.
332           * The file transfer connection remains open for result response only.           * The file transfer connection remains open for result response only.
333           * This connection is invalid and no further commands may be issued.           * This connection is invalid and no further commands may be issued.
# Line 356  public class FTPConnection Line 356  public class FTPConnection
356      }      }
357    }    }
358    
359          /**    /**
360           * Initialise the data transfer process.           * Initialise the data transfer process.
361           */           */
362    protected void initialiseDTP() throws IOException    protected void initialiseDTP() throws IOException
# Line 470  public class FTPConnection Line 470  public class FTPConnection
470      dtp.setTransferMode(transferMode);      dtp.setTransferMode(transferMode);
471    }    }
472    
473          /**    /**
474           * Set passive mode.           * Set passive mode.
475           * @param flag true if we should use passive mode, false otherwise           * @param flag true if we should use passive mode, false otherwise
476           */           */
# Line 483  public class FTPConnection Line 483  public class FTPConnection
483      }      }
484    }    }
485    
486          /**    /**
487           * Returns the current representation type of the transfer data.           * Returns the current representation type of the transfer data.
488           * @return TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY           * @return TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY
489           */           */
# Line 492  public class FTPConnection Line 492  public class FTPConnection
492      return representationType;      return representationType;
493    }    }
494    
495          /**    /**
496           * Sets the desired representation type of the transfer data.     * Sets the desired representation type of the transfer data.
497           * @param type TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY           * @param type TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY
498           */           */
499    public void setRepresentationType(int type) throws IOException    public void setRepresentationType(int type) throws IOException
# Line 525  public class FTPConnection Line 525  public class FTPConnection
525      }      }
526    }    }
527    
528          /**    /**
529           * Returns the current file structure type.           * Returns the current file structure type.
530           * @return STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE           * @return STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE
531           */           */
# Line 534  public class FTPConnection Line 534  public class FTPConnection
534      return fileStructure;      return fileStructure;
535    }    }
536    
537          /**    /**
538           * Sets the desired file structure type.           * Sets the desired file structure type.
539           * @param structure STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE           * @param structure STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE
540           */           */
# Line 565  public class FTPConnection Line 565  public class FTPConnection
565      }      }
566    }    }
567    
568          /**    /**
569           * Returns the current transfer mode.           * Returns the current transfer mode.
570           * @return MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED           * @return MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED
571           */           */
# Line 574  public class FTPConnection Line 574  public class FTPConnection
574      return transferMode;      return transferMode;
575    }    }
576    
577          /**    /**
578           * Sets the desired transfer mode.           * Sets the desired transfer mode.
579           * @param mode MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED           * @param mode MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED
580           */           */
# Line 607  public class FTPConnection Line 607  public class FTPConnection
607      }      }
608    }    }
609    
610          /**    /**
611           * Retrieves the specified file.           * Retrieves the specified file.
612           * @param filename the filename of the file to retrieve           * @param filename the filename of the file to retrieve
613           * @return an InputStream containing the file content           * @return an InputStream containing the file content
# Line 647  public class FTPConnection Line 647  public class FTPConnection
647      }      }
648    }    }
649    
650          /**    /**
651           * Returns a stream for uploading a file.           * Returns a stream for uploading a file.
652           * If a file with the same filename already exists on the server, it will           * If a file with the same filename already exists on the server, it will
653           * be overwritten.           * be overwritten.
# Line 671  public class FTPConnection Line 671  public class FTPConnection
671      }      }
672    }    }
673    
674          /**    /**
675           * Returns a stream for uploading a file.           * Returns a stream for uploading a file.
676           * If a file with the same filename already exists on the server, the           * If a file with the same filename already exists on the server, the
677           * content specified will be appended to the existing file.           * content specified will be appended to the existing file.
# Line 695  public class FTPConnection Line 695  public class FTPConnection
695      }      }
696    }    }
697    
698          /**    /**
699           * This command may be required by some servers to reserve sufficient           * This command may be required by some servers to reserve sufficient
700           * storage to accommodate the new file to be transferred.           * storage to accommodate the new file to be transferred.
701           * It should be immediately followed by a <code>store</code> or           * It should be immediately followed by a <code>store</code> or
# Line 716  public class FTPConnection Line 716  public class FTPConnection
716      }      }
717    }    }
718    
719          /**    /**
720           * Renames a file.           * Renames a file.
721           * @param oldName the current name of the file           * @param oldName the current name of the file
722           * @param newName the new name           * @param newName the new name
# Line 752  public class FTPConnection Line 752  public class FTPConnection
752      }      }
753    }    }
754    
755          /**    /**
756           * Aborts the transfer in progress.           * Aborts the transfer in progress.
757           * @return true if a transfer was in progress, false otherwise           * @return true if a transfer was in progress, false otherwise
758           */           */
# Line 775  public class FTPConnection Line 775  public class FTPConnection
775      }      }
776    }    }
777    
778          /**    /**
779           * Causes the file specified to be deleted at the server site.           * Causes the file specified to be deleted at the server site.
780           * @param filename the file to delete           * @param filename the file to delete
781           */           */
# Line 796  public class FTPConnection Line 796  public class FTPConnection
796      }      }
797    }    }
798    
799          /**    /**
800           * Causes the directory specified to be deleted.           * Causes the directory specified to be deleted.
801           * This may be an absolute or relative pathname.           * This may be an absolute or relative pathname.
802           * @param pathname the directory to delete           * @param pathname the directory to delete
# Line 817  public class FTPConnection Line 817  public class FTPConnection
817      }      }
818    }    }
819    
820          /**    /**
821           * Causes the directory specified to be created at the server site.           * Causes the directory specified to be created at the server site.
822           * This may be an absolute or relative pathname.           * This may be an absolute or relative pathname.
823           * @param pathname the directory to create           * @param pathname the directory to create
# Line 838  public class FTPConnection Line 838  public class FTPConnection
838      }      }
839    }    }
840    
841          /**    /**
842           * Returns the current working directory.           * Returns the current working directory.
843           */           */
844    public String getWorkingDirectory() throws IOException    public String getWorkingDirectory() throws IOException
# Line 869  public class FTPConnection Line 869  public class FTPConnection
869      }      }
870    }    }
871    
872          /**    /**
873           * Returns a listing of information about the specified pathname.           * Returns a listing of information about the specified pathname.
874           * If the pathname specifies a directory or other group of files, the           * If the pathname specifies a directory or other group of files, the
875           * server should transfer a list of files in the specified directory.           * server should transfer a list of files in the specified directory.
# Line 901  public class FTPConnection Line 901  public class FTPConnection
901      }      }
902    }    }
903    
904          /**    /**
905           * Returns a directory listing. The pathname should specify a           * Returns a directory listing. The pathname should specify a
906           * directory or other system-specific file group descriptor; a null           * directory or other system-specific file group descriptor; a null
907           * argument implies the user's current working or default directory.           * argument implies the user's current working or default directory.
# Line 939  public class FTPConnection Line 939  public class FTPConnection
939      }      }
940    }    }
941    
942          /**    /**
943           * Returns the type of operating system at the server.           * Returns the type of operating system at the server.
944           */           */
945    public String system() throws IOException    public String system() throws IOException
# Line 959  public class FTPConnection Line 959  public class FTPConnection
959      }      }
960    }    }
961    
962          /**    /**
963           * Does nothing.           * Does nothing.
964           * This method can be used to ensure that the connection does not time           * This method can be used to ensure that the connection does not time
965           * out.           * out.
# Line 978  public class FTPConnection Line 978  public class FTPConnection
978    
979    // -- I/O --    // -- I/O --
980    
981          /**    /**
982           * Sends the specified command line to the server.           * Sends the specified command line to the server.
983           * The CRLF sequence is automatically appended.           * The CRLF sequence is automatically appended.
984           * @param cmd the command line to send           * @param cmd the command line to send
# Line 991  public class FTPConnection Line 991  public class FTPConnection
991      out.flush();      out.flush();
992    }    }
993    
994          /**    /**
995           * Reads the next response from the server.           * Reads the next response from the server.
996           * If the server sends the "transfer complete" code, this is handled here,           * If the server sends the "transfer complete" code, this is handled here,
997           * and the next response is passed to the caller.           * and the next response is passed to the caller.
# Line 1008  public class FTPConnection Line 1008  public class FTPConnection
1008      return response;      return response;
1009    }    }
1010    
1011          /**    /**
1012           * Reads and parses the next response from the server.           * Reads and parses the next response from the server.
1013           */           */
1014    protected FTPResponse readResponse() throws IOException    protected FTPResponse readResponse() throws IOException

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26