home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / ftp / IftpClient.java < prev   
Encoding:
Java Source  |  1997-01-27  |  2.7 KB  |  93 lines

  1. /*
  2.  * @(#)IftpClient.java    1.13 95/08/29 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.net.ftp;
  21.  
  22. import java.io.*;
  23. import java.net.*;
  24.  
  25. /**
  26.  * Create an FTP client that uses a proxy server to cross a network
  27.  * firewall boundary.
  28.  *
  29.  * @version     1.13, 08/29/95
  30.  * @author    Jonathan Payne
  31.  * @see FtpClient
  32.  */
  33. public class IftpClient extends FtpClient {
  34.     public static final int IFTP_PORT = 4666;
  35.  
  36.     /** The proxyserver to use */
  37.     String  proxyServer = "sun-barr";
  38.     String  actualHost = null;
  39.     
  40.     /**
  41.      * Open an FTP connection to host <i>host</i>.
  42.      */
  43.     public void openServer(String host) throws IOException {
  44.     if (!serverIsOpen())
  45.         super.openServer(proxyServer, IFTP_PORT);
  46.     actualHost = host;
  47.     }
  48.  
  49.     boolean checkExpectedReply() throws IOException {
  50.     return readReply() != FTP_ERROR;
  51.     }
  52.  
  53.     /** 
  54.      * login user to a host with username <i>user</i> and password 
  55.      * <i>password</i> 
  56.      */
  57.     public void login(String user, String password) throws IOException {
  58.     if (!serverIsOpen()) {
  59.         throw new FtpLoginException("not connected to host");
  60.     }
  61.     user = user + "@" + actualHost;
  62.     this.user = user;
  63.     this.password = password;
  64.     if (issueCommand("USER " + user) == FTP_ERROR ||
  65.         lastReplyCode == 220 && !checkExpectedReply()) {
  66.         throw new FtpLoginException("user");
  67.     }
  68.     if (password != null && issueCommand("PASS " + password) == FTP_ERROR) {
  69.         throw new FtpLoginException("password");
  70.     }
  71.     }
  72.  
  73.     /**
  74.      * change the proxyserver from the default.
  75.      */
  76.     public void setProxyServer(String proxy) throws IOException {
  77.     if (serverIsOpen())
  78.         closeServer();
  79.     proxyServer = proxy;
  80.     }
  81.  
  82.     /**
  83.      * Create a new IftpClient handle.
  84.      */
  85.     public IftpClient(String host) throws IOException {
  86.     super();
  87.     openServer(host);
  88.     }
  89.  
  90.     /** Create an uninitialized client handle */
  91.     public IftpClient() {}
  92. }
  93.