<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 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    FtpClient的上傳,下載等操作

    Posted on 2008-03-22 14:38 semovy 閱讀(808) 評(píng)論(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("中草藥", "一起走過(guò)的日子");
      list(ftp);
      ftp.cd("一起走過(guò)的日子");
      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();
     }
    }

    主站蜘蛛池模板: 色欲色欲天天天www亚洲伊| 国产成人免费AV在线播放| 亚洲人成无码www久久久| 99久久国产精品免费一区二区| 亚洲精品白色在线发布| 国产一区二区三区在线免费观看 | 免费观看四虎精品成人| 亚洲AV无码国产精品麻豆天美 | 久久亚洲国产成人影院| 亚洲精品国产自在久久| 欧洲一级毛片免费| 一区二区三区精品高清视频免费在线播放| 亚洲AV永久无码精品一百度影院| 日本精品人妻无码免费大全| 久久精品成人免费国产片小草| 亚洲婷婷综合色高清在线| 亚洲精品无码av天堂| 日韩不卡免费视频| 国产成人无码免费网站| 亚洲最大av资源站无码av网址| 亚洲中文字幕久久精品无码喷水 | 亚洲黄色一级毛片| gogo全球高清大胆亚洲| 日韩欧毛片免费视频| 暖暖日本免费中文字幕| 国产精品亚洲а∨天堂2021| 亚洲成人福利在线| 亚洲夜夜欢A∨一区二区三区| 成人av免费电影| 亚洲网站在线免费观看| AAAAA级少妇高潮大片免费看| 亚洲av无码成人影院一区| 亚洲高清美女一区二区三区| 国产亚洲精品成人AA片新蒲金 | 日本特黄a级高清免费大片| 最近最新高清免费中文字幕| 国产特黄一级一片免费| 亚洲A∨精品一区二区三区下载| 亚洲欧洲尹人香蕉综合| 久久精品视频亚洲| 亚洲日本乱码在线观看|