中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Ftp與NFS服務(wù)器端上傳和下載

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
本功能實現(xiàn)FTP和NFS服務(wù)器上的文件傳輸,應(yīng)用Apache提供的 方法 commons-vfs2工具
import java.io.File;
 
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.Selectors;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
public class DownOrUpLoad {
   public static Logger logger = LoggerFactory.getLogger(DownOrUpLoad.class);
 
/**
     * 上傳文件到本地路徑
     * 
     * @param remotePath 遠程服務(wù)器上的路徑
     * @param tempApkPath 本地路徑
     */
   private void uploadAPk(final String tempApkPath,final String remotePath){
        switch (protocols) {
        case  "nfs" :
            uploadAPk_nfs(tempApkPath,remotePath);
            break;
        case "ftp" :
            uploadAPk_ftp(tempApkPath,remotePath);
            break;
        default:
            break;
        }    
    }
     
    private void uploadAPk_ftp(final String tempApkPath,final String remotePath){
        logger.info("upload file {} to {} ",tempApkPath,remotePath);
        try{
            final String ftpConnect=ftpPath;
            StandardFileSystemManager fsManager = new StandardFileSystemManager();
            fsManager.init();
             
            FileObject destFile = fsManager.resolveFile(ftpConnect+remotePath);
             
            if(destFile.exists()){
                destFile.createFile();
            }
            FileObject src = fsManager.resolveFile(tempApkPath);
            destFile.copyFrom(src, Selectors.SELECT_FILES);
             
            src.close();destFile.close();fsManager.close();
             
        }catch(Exception e){
            e.printStackTrace();
        }
    }
     
    private void uploadAPk_nfs(final String tempApkPath,final String remotePath){
        logger.info("upload file {} to {} ",tempApkPath,remotePath);
        try {
            FileUtils.copyFile(new File(tempApkPath),new File(nfsPath+remotePath));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
     
    /**
     * 下載遠程服務(wù)器apk到本地路徑
     * 
     * @param remoteApkPath 遠程服務(wù)器上的路徑
     * @return 本地路徑
     */
    private String downloadAPKtoLocalTempPath(final String remoteApkPath){
        switch (protocols) {
        case  "nfs" :
            return downloadAPK_NFS(remoteApkPath);
        case "ftp" :
            return downloadAPk_FTP(remoteApkPath);
        default:
            return "";
        }    
    }
     
    private  String downloadAPK_NFS(String remoteApkPath){
        File srcFile=new File(remoteApkPath);
        File descFile=new File(apkLocalPath+FilenameUtils.getName(remoteApkPath));
        try {
            if(srcFile.exists()){
                FileUtils.copyFile(srcFile, descFile);
                return descFile.getAbsolutePath();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
         
         
    }
     
    private  String downloadAPk_FTP(final String remoteApkPath){
        try{
            final String ftpConnect=ftpPath;
            StandardFileSystemManager fsManager = new StandardFileSystemManager();
            fsManager.init();
            File descFile=new File(apkLocalPath+FilenameUtils.getName(remoteApkPath));
            FileObject dest = fsManager.resolveFile(descFile.getAbsolutePath());
            if(dest.exists()){
                dest.createFile();
            }
            FileObject src = fsManager.resolveFile(ftpConnect+remoteApkPath);
            dest.copyFrom(src, Selectors.SELECT_FILES);
             
            src.close();dest.close();fsManager.close();
             
            return descFile.getAbsolutePath();
        }catch(Exception e){
            e.printStackTrace();
        }
         
        return "";
         
    }
     
}

標簽: 服務(wù)器

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇: 一些格式的Java工具類

下一篇: ImageView顯示網(wǎng)絡(luò)圖片資源