2013-06-13 197 views

回答

1

有使用工具的文件夾壓縮成zip文件(你的Linux節點上):

zip -r temp.zip /home/tmp 

它是傳遞到本地爲使用SFTP簡單的單文件之後。 最後在Windows機器上解壓縮(使用java.util.zip)。

/** 
* Unzip it 
* @param zipFile input zip file 
* @param output zip file output folder 
*/ 
public void unZipFolder(String zipFile, String outputFolder){ 

byte[] buffer = new byte[1024]; 

try{ 

    //create output directory is not exists 
    File folder = new File(OUTPUT_FOLDER); 
    if(!folder.exists()){ 
     folder.mkdir(); 
    } 

    //get the zip file content 
    ZipInputStream zis = 
     new ZipInputStream(new FileInputStream(zipFile)); 
    //get the zipped file list entry 
    ZipEntry ze = zis.getNextEntry(); 

    while(ze!=null){ 

     String fileName = ze.getName(); 
     File newFile = new File(outputFolder + File.separator + fileName); 

     System.out.println("file unzip : "+ newFile.getAbsoluteFile()); 

     //create all non exists folders 
     //else you will hit FileNotFoundException for compressed folder 
     new File(newFile.getParent()).mkdirs(); 

     FileOutputStream fos = new FileOutputStream(newFile);    

     int len; 
     while ((len = zis.read(buffer)) > 0) { 
     fos.write(buffer, 0, len); 
     } 

     fos.close(); 
     ze = zis.getNextEntry(); 
    } 

    zis.closeEntry(); 
    zis.close(); 

    System.out.println("Done"); 

}catch(IOException ex){ 
    ex.printStackTrace(); 
} 
} 
4

一個選項是通過ssh服務器。爲此,你必須在Linux系統上安裝ssh服務器(用於Ubuntu的openssh)和窗口(例如:winscp)。之後,您可以通過scp命令傳輸文件。查看詳細Transferring files over SSH

+0

我只使用scp cmd,但我不知道如何給目的地 – sasuke

相關問題