FTP在Heroku上超时 [英] FTP timing out on Heroku

查看:67
本文介绍了FTP在Heroku上超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Apache Commons FTPClient 在我的本地计算机上可以正常工作,但是在Heroku上运行时总是超时.相关代码:

Using Apache Commons FTPClient in a Scala application works as expected on my local machine, but always times out when running on Heroku. Relevant code:

val ftp = new FTPClient
ftp.connect(hostname)
val success = ftp.login(username, pw)
if (success) {
  ftp.changeWorkingDirectory(path)
  //a logging statement here WILL print
  val engine = ftp.initiateListParsing(ftp.printWorkingDirectory)
  //a logging statement here will NOT print
  while (engine.hasNext) {
    val files = engine.getNext(5)
    //do stuff with files
  }
}

通过添加一些日志记录,我已经确认客户端 已成功连接,登录和更改目录.但是在尝试开始检索文件时停止(通过上述页面访问或通过 ftp.listFiles 取消页面访问),并抛出连接超时异常(大约15分钟后).

By adding some loggings I've confirmed the client is successfully connecting, logging in, and changing the directory. But stops when trying to begin retrieving files (either via the above paged access or unpaged with ftp.listFiles) and throws a connection time out exception (after about 15 minutes).

任何原因上述代码在本地都可以正常运行,但不能在Heroku上运行?

Any reason the above code works fine locally but not on Heroku?

推荐答案

原来FTP有两种模式,处于活动状态和被动,以及Apache-Commons的 FTPClient 默认为活动状态.Heroku的防火墙大概不允许活动的FTP(这就是为什么它不能在本地正常运行,但是一旦部署就无法使用的原因)-通过添加 ftp.enterLocalPassiveMode()更改为被动模式可以解决此问题.

Turns out FTP has two modes, active and passive, and Apache-Commons' FTPClient defaults to active. Heroku's firewall presumably doesn't allow active FTP (which is why this was functioning properly locally but not once deployed) - changing to passive mode by adding ftp.enterLocalPassiveMode() resolved the issue.

这篇关于FTP在Heroku上超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆