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

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

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

    posts - 11,comments - 17,trackbacks - 0
    import ?java.io.InputStream;
    import ?java.util.Properties;

    import ?org.apache.commons.net.ftp.FTPClient;
    import ?org.apache.commons.net.ftp.FTPClientConfig;
    import ?org.apache.commons.net.ftp.FTPReply;
    import ?org.uranus.util.StringUtils;

    /**
    *?基于apache組織的commonNet開源組件實(shí)現(xiàn)ftp客戶端<br>
    *?本程序運(yùn)行依賴于一個(gè)config成員變量屬性,其是一個(gè)屬性(Properties)對(duì)象<br>
    *?系統(tǒng)要求這個(gè)config對(duì)象,必需有如下屬性key:<br>
    *?server(ftp服務(wù)器ip地址或域名)<br>
    *?username(登錄用戶名)<br>
    *?password(登錄密碼)<br>
    *?如下屬性key是可選的:<br>
    *?systemKey(ftp服務(wù)器的操作系統(tǒng)key,如window)<br>
    *?serverLanguageCode(ftp服務(wù)器使用的語言,如zh)<br>
    *?<br>
    *?本程序是線程安全,在每一個(gè)上傳時(shí)都將創(chuàng)建ftp連接,上傳結(jié)束后再關(guān)閉ftp連接<br>
    *
    *?例子:<br>
    *?InputStream?localIn?=?new?FileInputStream("c:\\計(jì)算機(jī).txt");<br>
    *
    *?java.util.Properties?config?=?new?Properties();<br>
    *?config.setProperty("server",?"192.168.5.120");<br>
    *?config.setProperty("username",?"upload");<br>
    *?config.setProperty("password",?"upload");<br>
    *
    *?FtpClientCommonNetImpl?client?=?new?FtpClientCommonNetImpl();<br>
    *?client.setConfig(config);<br>
    *?client.upload(localIn,?"/aaa/計(jì)算機(jī).txt",?true);<br>
    *
    *
    *?
    @author ?zhangdb
    *
    */

    public ? class ?FtpClientCommonNetImpl? implements ?IFtpClient? {
    // ?ftp配置
    private ?Properties?config;

    /**
    *?連接到ftp服務(wù)器
    *
    *?
    @param ?server
    *?
    @param ?userName
    *?
    @param ?password
    *?
    @return
    *?
    @throws ?FtpException
    */

    protected ?FTPClient?connectFtpServer(String?server,?String?userName,
    String?password)?
    throws ?FtpException? {
    // ?創(chuàng)建ftp客戶端對(duì)象
    FTPClient?ftp? = ? new ?FTPClient();
    try ? {
    ftp.configure(
    this .getFTPClientConfig());
    // ?連接ftp服務(wù)器
    ftp.connect(server);
    // ?登錄
    ftp.login(userName,?password);

    // ?返回值
    int ?reply? = ?ftp.getReplyCode();
    if ?(( ! FTPReply.isPositiveCompletion(reply)))? {
    ftp.disconnect();
    throw ? new ?FtpException( " 登錄ftp服務(wù)器失敗,請(qǐng)檢查server[ " ? + ?server
    + ? " ]、username[ " ? + ?userName? + ? " ]、password[ " ? + ?password
    + ? " ]是否正確! " );
    }


    return ?ftp;
    }
    ? catch ?(Exception?ex)? {
    throw ? new ?FtpException(ex);
    }

    }


    /**
    *?關(guān)閉連接
    *
    *?
    @param ?ftp
    */

    protected ? void ?disconnectFtpServer(FTPClient?ftp)? {
    try ? {
    ftp.logout();
    ftp.disconnect();
    }
    ? catch ?(Exception?ex)? {
    throw ? new ?FtpException(ex);
    }

    }


    /**
    *?上傳
    */

    public ? void ?upload(InputStream?localIn,?String?remoteFilePath)
    throws ?FtpException? {
    String?server?
    = ? this .config.getProperty( " server " );
    String?userName?
    = ? this .config.getProperty( " username " );
    String?password?
    = ? this .config.getProperty( " password " );
    FTPClient?ftp?
    = ? this .connectFtpServer(server,?userName,?password);

    try ? {
    boolean ?result? = ?ftp.storeFile( this
    .enCodingRemoteFilePath(remoteFilePath),?localIn);
    if ?( ! result)? {
    throw ? new ?FtpException( " 文件上傳失敗! " );
    }

    }
    ? catch ?(Exception?ex)? {
    throw ? new ?FtpException(ex);
    }
    ? finally ? {
    this .disconnectFtpServer(ftp);
    }

    }


    /**
    *?上傳結(jié)束以后關(guān)閉輸入流
    *
    *?
    @param ?localIn
    *?
    @param ?remoteFilePath
    *?
    @param ?afterUploadCloseInputStream
    *?
    @throws ?FtpException
    */

    public ? void ?upload(InputStream?localIn,?String?remoteFilePath,
    boolean ?afterUploadCloseInputStream)? throws ?FtpException? {
    try ? {
    // ?上傳
    this .upload(localIn,?remoteFilePath);
    }
    ? finally ? {
    if ?(afterUploadCloseInputStream)? {
    if ?(localIn? != ? null )? {
    try ? {
    localIn.close();
    }
    ? catch ?(Exception?ex)? {
    throw ? new ?FtpException(ex);
    }

    }

    }

    }

    }


    /**
    *?得到配置
    *
    *?
    @return
    */

    protected ?FTPClientConfig?getFTPClientConfig()? {
    // ?創(chuàng)建配置對(duì)象
    FTPClientConfig?conf? = ? new ?FTPClientConfig( this .config.getProperty(
    " systemKey " ,?FTPClientConfig.SYST_NT));
    conf.setServerLanguageCode(
    this .config.getProperty(
    " serverLanguageCode " ,? " zh " ));
    return ?conf;
    }


    /**
    *?遠(yuǎn)程文件路徑編碼(上傳到ftp上的文件路徑)
    *
    *?
    @param ?remoteFilePath
    *?
    @return
    */

    protected ?String?enCodingRemoteFilePath(String?remoteFilePath)? {
    return ?StringUtils.gbkToIso8859EnCoding(remoteFilePath);
    }


    public ?Properties?getConfig()? {
    return ?config;
    }


    public ? void ?setConfig(Properties?config)? {
    this .config? = ?config;
    }


    }
    ?
    posted on 2007-03-28 19:42 Ken.Lee 閱讀(1064) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 四虎永久免费地址在线观看| eeuss影院ss奇兵免费com| 又粗又大又黑又长的免费视频 | 精品久久久久久亚洲精品| 香蕉97超级碰碰碰免费公| 免费一级做a爰片性色毛片| 亚洲性色AV日韩在线观看| 毛片免费观看的视频| 亚洲真人无码永久在线观看| 免费一本色道久久一区| 亚洲AV成人影视在线观看| 成人性生交视频免费观看| 日韩亚洲国产高清免费视频| 成人奭片免费观看| 日韩国产欧美亚洲v片| 日本不卡在线观看免费v| 国外成人免费高清激情视频 | 亚洲国产综合人成综合网站| 香蕉视频免费在线播放| 在线成人爽a毛片免费软件| 亚洲小视频在线播放| 亚洲五月午夜免费在线视频| 亚洲精品午夜无码电影网| 无码少妇精品一区二区免费动态 | 在线看片人成视频免费无遮挡| 亚洲AV永久无码天堂影院| 亚洲AV中文无码乱人伦在线视色| sihu国产精品永久免费| 亚洲综合一区二区国产精品| 亚洲人成电影网站免费| 免费一级特黄特色大片| 日本高清免费不卡视频| 一区二区三区免费在线观看| 亚洲男人第一av网站| 精品免费国产一区二区三区| A国产一区二区免费入口| 亚洲国产夜色在线观看| 亚洲国产精品人人做人人爽| 中文字幕免费高清视频| 国产av无码专区亚洲av毛片搜| 久久精品国产亚洲麻豆|