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

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

问题描述

使用 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 有两种模式,active和被动,以及 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.

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

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