FTP timing out on Heroku

≡放荡痞女 提交于 2021-02-11 18:09:30

问题


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
  }
}

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).

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


回答1:


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.



来源:https://stackoverflow.com/questions/19935068/ftp-timing-out-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!