【发布时间】:2016-03-21 15:59:30
【问题描述】:
我正在尝试在我的测试中从 FTP 下载文件。 当我从本地 PC 或 BrowserStack 上运行它时,它运行良好,但是当我将它上传到 jenkins 时,它卡在了队列中。 我不明白为什么它不在詹金斯上运行有什么区别? 我设法创建了到 FTP 的连接。下面显示的代码是下载文件的方法。
布尔成功 = 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;
}
【问题讨论】:
标签: java selenium jenkins ftp ftp-client