6

When I log in to SSH while forwarding my local port, it's 21 FTP port, with the command:

ssh -R 2101:localhost:21 [email protected] -p 8288

After successfully logging in, I sent this command in the SSH:

ftp ikiw@localhost -p 2101

The command runs normally, and I also successfully logged into FTP smoothly, but when in FTP, I want to see a list of files available with the command ls or dir and I get this error:

ftp: Can't connect to '::1:27394': Connection refused

What is wrong? Does it seem like FTP creates a new port randomly when I run the ls command?

I want to forward my local FTP to my SSH/VPS, and run FTP from my SSH/VPS to my local machine normally, can someone help me and provide a solution? Thank you very much! :D

2 Answers 2

28

FTP is a horrible protocol. Yes, it uses multiple ports; there's the control port and then each data transfer (ls or get and so on) opens a second new random port.

Worse, depending on if you're doing PASV or active mode FTP, the server could try to initiate the connection.

FTP isn't easy to handle with forwarding like this. Since you have ssh connectivity, can't you use sftp? That's an FTP-like protocol that's built directly into ssh so no need to port forward.

5
  • actually I just want to separate the connection between FTP and SFTP (SSH), but if it turns out this is quite difficult to do, then I will just follow your advice and use SFTP. Thank You for taking your time to answer my question!
    – TuanHaxor
    Dec 29, 2023 at 19:22
  • 14
    "FTP is a horrible protocol" – Related: FTP Must Die. Dec 29, 2023 at 19:41
  • 1
    @TuanHaxor what is your goal behind "separate the connection"? (There might be a different way to achieve that.) Dec 30, 2023 at 23:41
  • 3
    FTP has been designed around a use case that is uncommon today: server-to-server transfers. It is possible for a client to open two control connections and tell one server to send the file to the other. The downside of this is that it is difficult to get through a firewall, anyone who's ever deployed SIP based telephony infrastructure might recognize the issues. Dec 31, 2023 at 7:34
  • @Paŭlo Ebermann There is no specific goal bro
    – TuanHaxor
    Dec 31, 2023 at 14:29
-3

FTP appears to be trying to use IP6, but you've only tunneled IP4. Try starting ftp with the -4 option.

1
  • 1
    You’re correct that’s an IPv6 address but it’s localhost, so not the problem. The issue is that FTP can’t open a connection for data because it’s not able to be tunneled in this way (Steven’s answer)
    – Josh
    Dec 30, 2023 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .