<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 0, comments - 77, trackbacks - 0, articles - 356
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    FtpClient的上傳,下載等操作

    Posted on 2008-03-22 14:38 semovy 閱讀(808) 評論(0)  編輯  收藏 所屬分類: JAVA應(yīng)用

    package com.semovy.test;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;

    import sun.net.TelnetInputStream;
    import sun.net.TelnetOutputStream;
    import sun.net.ftp.FtpClient;

    public class FTPTest extends FtpClient {

     public void connectServer(String server, String user, String password,
       String path) throws Exception {
      openServer(server);
      login(user, password);
      System.out.println("login   success!");
      if (path.length() != 0)
       cd(path);
      binary();
     }

     // 向ftp服務(wù)器發(fā)送操作命令
     public void sendCommand(String command) throws IOException {
      issueCommand(command);
     }

     // 刪除文件
     public void deleteFile(String fileName) throws IOException {
      issueCommand("DELE " + fileName);
     }

     public void closeConnect() {
      try {
       closeServer();
      } catch (IOException ex) {
       ex.printStackTrace();
      }
     }

     public void upload(String localFilePath, String remoteFilePath) {
      try {
       TelnetOutputStream os = put(remoteFilePath);
       File file_in = new File(localFilePath);
       FileInputStream is = new FileInputStream(file_in);
       byte[] bytes = new byte[1024];
       int ch;
       while ((ch = is.read(bytes)) != -1) {
        os.write(bytes, 0, ch);
       }
       is.close();
       os.close();
       System.out.println("upload file successfully.");
      } catch (IOException e) {
       e.printStackTrace();
      }
     }

     public void download(String localFilePath, String remoteFilePath) {
      try {
       int ch;
       File fi = new File(localFilePath);
       OutputStream out = new FileOutputStream(fi);
       TelnetInputStream fget = get(remoteFilePath);
       byte[] b = new byte[1024];
       int len = 0;
       while ((len = fget.read(b)) != -1) {
        out.write(b, 0, len);
       }
       fget.close();
       out.close();
       System.out.println("download file successfully.");
      } catch (IOException e) {
       e.printStackTrace();
      }
     }
     public static void list(FtpClient ftp)throws Exception
     {
      InputStream in = ftp.list();
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      String temp = null;
      while((temp = reader.readLine()) != null)
      {
       
       System.out.println(temp);
      }
      in.close();
     }
     public static void main(String[] args) throws Exception {
      FTPTest ftp = new FTPTest();
      ftp.connectServer("teckotooling.vicp.net", "admin", "admin", "");
      String localFilePath = "d:/iReport-2.0.5-windows-installer.exe";
      String remoteFilePath = "iReport-2.0.5-windows-installer.exe";
      ftp.upload(localFilePath,remoteFilePath);
      ftp.download(localFilePath, remoteFilePath);
      ftp.deleteFile("AI_CS3_chs.exe");
      ftp.rename("中草藥", "一起走過的日子");
      list(ftp);
      ftp.cd("一起走過的日子");
      list(ftp);
      ftp.cdUp();
      list(ftp);
      System.out.println("ftp.getLocalAddress(): " + ftp.getLocalAddress());
      System.out.println("ftp.welcomeMsg: " + ftp.welcomeMsg);
      System.out.println("ftp.getConnectTimeout(): " + ftp.getConnectTimeout());
      System.out.println("ftp.getReadTimeout(): " + ftp.getReadTimeout());
      System.out.println("ftp.system(): " + ftp.system());
      System.out.println("ftp.FTP_PORT: " + ftp.FTP_PORT);
      System.out.println("ftp.encoding: " + ftp.encoding);
      System.out.println("ftp.getFtpProxyHost(): " + ftp.getFtpProxyHost());
      System.out.println("ftp.serverIsOpen(): " + ftp.serverIsOpen());
      ftp.closeConnect();
     }
    }

    主站蜘蛛池模板: 国产AV旡码专区亚洲AV苍井空| 久久久久久av无码免费看大片| 免费jjzz在在线播放国产| 一级毛片免费在线| 亚洲一二成人精品区| 日本免费网站观看| 成在人线av无码免费高潮喷水| 亚洲AV无码成人专区| 亚洲精品无码久久毛片| 91精品国产免费久久久久久青草| 国产成人亚洲综合无| 老司机亚洲精品影院| 免费一级大黄特色大片| 免费A级毛片无码视频| 老司机亚洲精品影院在线观看| 亚洲国产成人久久综合一| 免费A级毛片无码久久版| 免费观看国产网址你懂的| 免费又黄又爽又猛大片午夜 | 狼友av永久网站免费观看| 色播在线永久免费视频网站| 亚洲xxxx视频| 亚洲激情中文字幕| 亚洲伊人成无码综合网 | 一级人做人爰a全过程免费视频| 亚洲欧洲日产国码在线观看| 亚洲精品国产综合久久一线| 免费a级毛片无码a∨蜜芽试看| 免费无码作爱视频| 香蕉视频免费在线播放| 精品国产日韩久久亚洲| 亚洲AV天天做在线观看| 亚洲一级特黄无码片| 国产无遮挡吃胸膜奶免费看| 四虎精品视频在线永久免费观看| 两个人看的www免费高清| 香蕉视频免费在线播放| 亚洲国产欧美一区二区三区| 亚洲国产成人综合| 亚洲精品视频免费看| 亚洲bt加勒比一区二区|