Package sun.net.ftp

Examples of sun.net.ftp.FtpClient


   */
  public static final Any ftpPut(String urlString, Any anyData, int type)
      throws IOException, UnserializationException
  {
    FtpURL  ftpURL = new FtpURL(urlString);
    FtpClient ftpClient = new FtpClient(ftpURL.host);
    ftpClient.login(ftpURL.user,ftpURL.pass);
    ftpClient.binary();
    ftpClient.cd(ftpURL.dir);

    BufferedWriter writer;
    Any result;

    switch (type) {

    case StreamUtils.TYPE_STRING:
      writer = new BufferedWriter(new OutputStreamWriter(ftpClient.put(ftpURL.file)));
      writer.write(anyData.toString());
      writer.close();
      result = Any.TRUE;
      break;

    case StreamUtils.TYPE_LINES:
      writer = new BufferedWriter(new OutputStreamWriter(ftpClient.put(ftpURL.file)));
      result = StreamUtils.linesToWriter(anyData,writer);
      break;

    case StreamUtils.TYPE_BINARY:
      OutputStream out = ftpClient.put(ftpURL.file);
      byte[] byteArray = (byte[])(anyData.toObject());
      out.write(byteArray);
      out.close();
      result = Any.TRUE;
      break;

    case StreamUtils.TYPE_DATA:
      OutputStream outs = ftpClient.put(ftpURL.file);
      Serialization.serialize(null, anyData, outs);
      outs.close();
      result = Any.TRUE;
      break;

    default:
      result = Any.FALSE;
      break;
    }
    try {
      ftpClient.closeServer();
    } catch (Exception e) {
      //anvil.Log.log().error("Can not close ftp connection");
    }
    return result;
  }
View Full Code Here


   */
  public static final Any ftpPutString(String urlString, String string)
      throws IOException, UnserializationException
  {
    FtpURL  ftpURL  = new FtpURL(urlString);
    FtpClient ftpClient = new FtpClient(ftpURL.host);
    ftpClient.login(ftpURL.user,ftpURL.pass);
    ftpClient.binary();
    ftpClient.cd(ftpURL.dir);

    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ftpClient.put(ftpURL.file)));
    writer.write(string);
    writer.close();
    Any result = Any.TRUE;
    try {
      ftpClient.closeServer();
    } catch (Exception e) {
      //anvil.Log.log().error("Can not close ftp connection");
    }
    return result;
  }
View Full Code Here

  /// @throws IOError if an IO error occured
  public static final Object[] newInstance = { null, "*address", null, "*port", new Integer(0) };
  public static final Any newInstance(Context context, Any host, int port)
  {
    try {
      FtpClient client;
      if (host != null) {
        String hostname;
        if (host instanceof AnyInetAddress) {
          hostname = ((InetAddress)host.toObject()).getHostName();
        } else {
          hostname = host.toString();
        }
        if (port == 0) {
          port = FtpClient.FTP_PORT;
        }
        context.checkConnect(hostname, port);
        client = new FtpClient(hostname, port);
      } else {
        client = new FtpClient();
      }
      return new AnyFtpClient(client);
    } catch (IOException e) {
      throw context.exception(e);
    }
View Full Code Here

                new GetPropertyAction("ftp.protocol.user",
                                      "Java" + vers +"@"));
        }
        try {
            if (p != null)
                ftp = new FtpClient(p);
            else
                ftp = new FtpClient();
            setTimeouts();
            if (port != -1)
                ftp.openServer(host, port);
            else
                ftp.openServer(host);
View Full Code Here

                "/ftpBenchmark/serverConfig/fileCount").trim());
        user = ctx.getProperty("user");
        password = ctx.getProperty("password");

        // Connect ftp client.
        ftpClient = new FtpClient();
        if (port == null || port.length() == 0) {
            ftpClient.openServer(host);
        } else {
            this.port = Integer.parseInt(port);
            ftpClient.openServer(host, this.port);
View Full Code Here

TOP

Related Classes of sun.net.ftp.FtpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.