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

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

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

    J2EE劍俠行

    直覺我的J2EE應用生涯,打造我心中的一把利劍。

    常用鏈接

    統計

    技術鏈接

    最新評論

    開源代碼:edtFTPj學習總結

    edtFTPj

    edtFTPj是一個FTP客戶端包它可以嵌入到應用程序中以便以提供FTP的功能.它提供一些方法如:put(),get(),chdir(),dir()與pwd()等來完成FTP的功能.

    通過對其的學習,尤其是取FILENAME是一個大的挑戰,我曾經為這個走了很多的冤枉路,我對其代碼總結。
    java代碼:
    package com.throuhout.j2eemodel.util;

    /**
    *  保留Enterprisedt公司信息
    *  Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
    *
    *  www.enterprisedt.com
    *
    *  This library is free software; you can redistribute it and/or
    *  modify it under the terms of the GNU Lesser General Public
    *  License as published by the Free Software Foundation; either
    *  version 2.1 of the License, or (at your option) any later version.
    *
    *  This library is distributed in the hope that it will be useful,
    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    *  Lesser General Public License for more details.
    *
    *  You should have received a copy of the GNU Lesser General Public
    *  License along with this library; if not, write to the Free Software
    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    *
    *  Bug fixes, suggestions and comments should be sent to support@enterprisedt.com
    * nether add by heweiya
    *  對FTP服務器的通用操作
    *  ConnFTPServer(String host,String username,String password)
    *  Upload(String localfile,String filename)
    *  Download(String localpath)
    *
    */

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.URL;

    import com.enterprisedt.net.ftp.FTPClient;
    import com.enterprisedt.net.ftp.FTPConnectMode;
    import com.enterprisedt.net.ftp.FTPException;
    import com.enterprisedt.net.ftp.FTPMessageCollector;
    import com.enterprisedt.net.ftp.FTPTransferType;
    import com.enterprisedt.util.debug.Logger;

    /**
    *  Simple test class for FTPClient
    *
    *  
    @author      Hans Andersen
    *  
    @author      Bruce Blackshaw
    */
    public class FtpClient {

            
    /**
            *  Log stream
            
    */
            
    private static Logger log = Logger.getLogger(FtpClient.class);
            
    private FTPClient ftp = null;
           
           
            
    public void ConnFTPServer(String host, String username, String password) {

                    
    try {
                            
    // set up client   
                            ftp = new FTPClient();
                            ftp.setRemoteHost(host);
                            FTPMessageCollector listener 
    = new FTPMessageCollector();
                            ftp.setMessageListener(listener);
                            
    //ftp.setAutoPassiveIPSubstitution(true);

                            
    // connect
                            log.info("Connecting");
                            ftp.connect();

                            
    // login
                            log.info("Logging in");
                            ftp.login(username, password);

                            
    // set up passive ASCII transfers
                            log.debug("Setting up passive, ASCII transfers");
                            ftp.setConnectMode(FTPConnectMode.ACTIVE);
                            ftp.setType(FTPTransferType.ASCII);

                    } 
    catch (Exception e) {
                            log.error(
    "Demo failed", e);
                    }
            }

            
    public void Upload(String localfile, URL url) {
                    String host 
    = url.getHost();
                    
    int port = url.getPort();
                    File filePath 
    = new File(url.getPath());
                    String directory 
    = filePath.getParent().substring(1);
                    String filename 
    = filePath.getName();
                    
    try {
                            
    //connect(host, port);
                            ftp.chdir(directory);
                            ftp.put(
    new FileInputStream(localfile), filename);
                    } 
    catch (Exception e) {
                            log.error(
    "Demo failed", e);
                    }
            }
           
            
    public void Upload(String localpath,String filename) {
                    
    try {
                            ftp.put(localpath, filename);
                    } 
    catch (Exception e) {
                            log.error(
    "Demo failed", e);
                    }
            }
           
            
    public void DownloadAll(String localpath){
                    
    try {
                            ftp.chdir(
    "xml");
                            String[] files 
    = ftp.dir("."true);

                            
    for (int i = 0; i < files.length; i++) {
                                    String testfile 
    = files[i].substring(39);//大家可以看到這里,testfile取μ貌皇?filename而是一個字條串,我?皇譴涌?的位置取得FILENAME,方法可能很笨,但是我不知道如何來取得真正的FILENAME。
                                    log.debug(files[i]);
                                    ftp.get(
    new FileOutputStream(localpath+testfile),testfile);
                                    
    //ftp.get(localpath + testfile, testfile);
                            }
                    } 
    catch (IOException e) {
                            
    // TODO 自動生成 catch 塊
                            e.printStackTrace();
                    } 
    catch (FTPException e) {
                            
    // TODO 自動生成 catch 塊
                            e.printStackTrace();
                    }

            }
        
    public void DisConn(){
                
    try {
                            ftp.quit();
                           
                    } 
    catch (IOException e) {
                            
    // TODO 自動生成 catch 塊
                            e.printStackTrace();
                    } 
    catch (FTPException e) {
                            
    // TODO 自動生成 catch 塊
                            e.printStackTrace();
                    }
        }



    posted on 2005-12-16 18:05 @家軍 閱讀(1212) 評論(0)  編輯  收藏 所屬分類: J2EE開源學習

    主站蜘蛛池模板: 中文字幕亚洲免费无线观看日本| 免费手机在线看片| 国产精品亚洲αv天堂无码| 五月天网站亚洲小说| 亚洲变态另类一区二区三区 | 2020久久精品国产免费| 亚洲国产日韩女人aaaaaa毛片在线| 亚洲精品国产高清在线观看| 又黄又爽又成人免费视频| 亚洲免费闲人蜜桃| 久久受www免费人成_看片中文| 亚洲av日韩av综合| 91福利免费网站在线观看| 日韩精品视频免费观看| 亚洲一区免费观看| 免费观看无遮挡www的视频| 久久精品国产69国产精品亚洲| 男女作爱在线播放免费网站| 亚洲Av无码国产情品久久| 亚洲Av高清一区二区三区| 成人免费无遮挡无码黄漫视频| 亚洲国产成人久久精品大牛影视| 国产又大又粗又硬又长免费| 亚洲avav天堂av在线不卡| 久久国产乱子免费精品| 亚洲国产美女视频| 免费播放特黄特色毛片| 最新亚洲成av人免费看| 亚洲理论片在线中文字幕| 日韩毛片免费在线观看| 国产免费福利体检区久久| 亚洲综合精品一二三区在线| 曰曰鲁夜夜免费播放视频| 国产亚洲综合精品一区二区三区| 亚洲理论电影在线观看| 色老头永久免费网站| 色天使亚洲综合一区二区| 免费无码黄动漫在线观看| 久久久久国色AV免费观看| 亚洲国产美女福利直播秀一区二区| 四虎影在线永久免费观看|