FTP fails to transmit data in passive mode – libcurl

ftplibcurl

Am trying to upload a file using libcurl in C. Data transmission is getting failed. Below is the log message.

How to fix this issue?

< 250 CWD command successful.

EPSV

  • Connect data stream passively
    < 500 'EPSV': command not understood
  • disabling EPSV usage

    PASV

< 227 Entering Passive Mode (x,x,x,x,193,152).

  • Trying x.x.x.x… * No route to host

  • couldn't connect to host

  • Closing connection #0

  • Couldn't connect to server

Best Answer

This means that when the FTP server opens a second port for your client to connect to, your client (libcurl) fails to reach it. It is most likely due to a firewall or other network equipment somewhere along the way that blocks your ability to do the request operation.

Alternative reasons could be a wrongly configured ftp server, but if it works for other users, that seems less likely.

Another reason for failure may be that you have an active firewall that doesn't know EPSV and thus gets confused by it and ruins it for you. Try without it by setting CURLOPT_FTP_USE_EPSV to 0.

You can try to the active approach instead (which is what most older style FTP clients do by default), which makes the client ask the server to connect back to you instead. You activate that in libcurl with CURLOPT_FTPPORT. (See the docs for exact details on how to use it.)