2016-03-21 93 views
0

我試圖在FTP測試中從FTP下載文件。 當我從我的本地PC或BrowserStack運行它時,它可以很好地工作,但當我將它上傳到jenkins時,它會陷入困境。 我不明白爲什麼不在詹金斯上運行有什麼區別? 我設法創建了一個到FTP的連接。下面顯示的代碼是下載文件的方法。從FTP下載文件在運行Jenkins時卡住

boolean success = ftpClient.retrieveFile(remoteFile,outputStream);

public static File downloadFileFromFtp(String fileName, String ftpFilePath, String downloadDirectory, String fileExtension, ExtentTest test) throws Exception { 
    FTPClient ftpClient = new FTPClient(); 
    ftpClient.connect(AutomationPropeties.ftpHost, Integer.valueOf(AutomationPropeties.ftpPort)); 
    ftpClient.login(AutomationPropeties.ftpUsername, AutomationPropeties.ftpPassword); 
    ftpClient.enterLocalPassiveMode(); 
    System.out.println("loged in ftp"); 
    if (ftpClient.isConnected()) { 
     test.log(LogStatus.INFO, "Connected Succesfuly to ftp server."); 
     System.out.println("loged in ftp"); 
    } else { 
     test.log(LogStatus.INFO, "Failed connecting to ftp."); 
     System.out.println("not loged in ftp"); 
    } 
    String remoteFile = ftpFilePath + fileName + ".xlsx"; 
    System.out.println(remoteFile); 
    // File downloadFile = new File(downloadDirectory+fileName+".xlsx"); 

    File downloadFile = File.createTempFile(fileName, ".xlsx"); 
    System.out.println("reached the try"); 
    try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadFile))) { 
     System.out.println("finished with the output"); 
     boolean success = ftpClient.retrieveFile(remoteFile, outputStream); 
     System.out.println("retrive the file & conection closed"); 
     if (success) { 
      test.log(LogStatus.PASS, "File was downloaded succesfuly"); 
     } else { 
      test.log(LogStatus.FAIL, "Failed to download file"); 
     } 
    } finally { 
     ftpClient.logout(); 
     ftpClient.disconnect(); 
    } 
    return downloadFile; 
} 

回答

0

也許詹金斯FTP plugin是你所需要的。詹金斯可以定義爲工蜂(比奴隸好得多,你不覺得嗎?)服務器,所以你的工作可以運行在不同的物理服務器上。

如果你看看插件,請回報如果有幫助。

更新

用途:

curl -O ftp://server/path/to/file 
+0

這是用於上傳文件,我需要在我的測試中從ftp下載一個文件。 – Nroiz

0

這是BrowserStack穆庫爾。我們最近發佈了一個Jenkins plugin,可能會幫助你。