SSH端口转发下,连接到远程服务器的FTP
- 远程Windows主机部署FTP Server服务(可通过FileZilla Server)
- 在FTP Server上配置“Passive Mode”,并指定端口为7781-7789(端口范围时网上的推荐)
- 远程Windows主机防火墙增加FileZilla的通过权限,并在inbound规则里开放7781-7789端口
- SSH端口转发本地端口7780到远端21端口,本地7781-7789端口映射远端7781-7789端口
- SSH登陆后(此时端口转发也已经生效),本地FTP客户端访问127.0.0.1:7780,填写server端设置好的用户名密码登陆即可。
- 正常使用FTP服务。
While this question is old, there's no really comprehensive answer. So I'm adding one.
In the passive FTP mode (the most common mode nowadays), the FTP server listens on port 21 for an FTP control connection. But for all data transfers, including directory listings, it listens on an additional port. The port is picked out of a configured port range.
If you open only the 21 control port on the firewall, you get the described behavior. You can connect, but you cannot list directories or transfer files.
For details, see my article on Network configuration for passive FTP mode.
You have to go to Control Panel > System and Security > Windows Firewall > Advanced Settings > Inbound Rules > New Rule and add a new inbound rule for data port range your FTP server is using.
The port range that the FileZilla FTP server is using, is configured in Edit > Settings > Passive mode settings > Use custom port rage. You can configure a narrow range (like 10 ports), to limit a number of opened ports. You should use port numbers 1024 and above (up to 65535).
For FTP you need to forward both "FTP" and "data" ports. You forwarded only the control port, passive mode needs another port(s).
I would recommend to forward port 7780 -> 21 and port range 7781-7789 -> 7781-7789.
In the first dialog set listen port 21, in the second tick "custom port settings" and type 7781-7789.