目前,我们的项目需要应用服务器访问服务提供商提供的ftp服务器。
我已经尝试了几种方法来解决这个问题,但都没有成功。我所做的是在NAT和应用程序安全组上打开一个端口范围,比如(40000-60000)以及标准ftp端口20-21。
用户认证可以通过,但我无法从应用服务器列出内容。
我能够从NAT访问ftp服务器,完全没有问题。
那么我该怎么做才能使其正常工作呢?
@JohnRotenstein 绝对正确,如果可以的话,你应该使用被动 FTP。但是如果像我一样,你被客户卡住,他们坚持要求你使用主动式FTP,因为他们想要你连接到的FTP站点自1990年以来一直在运行,现在更改它是完全不合理的,那么请继续阅读。
AWS的NAT服务器不支持处于私有子网中的机器使用主动式FTP进行连接。结束语。如果你问我,这是个漏洞,但如果你问AWS支持团队,他们会说这是一个不支持的功能。
我们最终想出的解决方案(并且有效)是:
Add a route in your operating system's networking configuration to only use the new public ENI
In windows, the command will look like this, assuming the evil active ftp server you're trying to connect to is at 8.1.1.1:
route add 8.1.1.1 mask 255.255.255.254 10.1.1.1 metric 2
This adds a route for all traffic to the FTP server at 8.1.1.1 using subnet mask 255.255.255.254 (ie. this IP and only this IP) should go to the internet gateway 10.1.1.1 using ethernet adapter 2 (your second NIC)
Fed up yet? Yeah, me too, but now comes the hard part. The OS doesn't know it's public IP address for the public EIN. So you need to teach your FTP client to send the PORT command with the public IP. For example if using CURL, use the --ftp-port command like so:
curl -v --ftp-port 54.54.54.54 ftp://8.1.1.1 --user myusername:mypass
完成!现在您可以从几乎完全位于私有子网中的EC2机器连接到恶梦般的活动FTP站点。
curl
部分。只需告诉--ftp-port
AWS分配给实例的公共IP即可。请注意,自7.19.5版本以来,您可以在IP之后指定范围。因此,现在用户不必打开所有端口,而只需在AWS防火墙中打开一个范围即可。 - jgomo3