【问题标题】:downloading file from FTP gets stuck when running Jenkins运行 Jenkins 时从 FTP 下载文件卡住
【发布时间】: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


    【解决方案1】:

    也许 Jenkins FTP plugin 是您所需要的。 Jenkins 可以用工蜂(比从机好得多,你不觉得吗?)服务器来定义,这样你的工作就可以在不同的物理服务器上运行。

    如果您查看该插件,请报告是否有帮助。

    更新

    用途:

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

    【讨论】:

    • 这是上传文件,我需要在我的测试中从ftp下载一个文件。
    【解决方案2】:

    这是来自 BrowserStack 的 Mukul。我们最近发布了一个Jenkins plugin,可能会对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 2017-07-29
      • 2014-08-05
      • 2014-11-06
      • 2020-06-22
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多