ftp_get: Illegal PORT command

后端 未结 1 631
天命终不由人
天命终不由人 2020-12-10 18:03

On \'localhost\' I tried to get a file from FTP server and the local file is successfully created. But when I\'m trying in Ubuntu server it\'s displaying there was a problem

相关标签:
1条回答
  • 2020-12-10 18:16

    The "Illegal PORT command" is a message issued by ProFTPD server, when it receives PORT command with an invalid IP address.

    What typically happens, when the client is behind a NAT and reports its internal IP address to the server, not knowing the server is not able to reach back to that IP address.

    The easiest (and generally correct) solution is to use an FTP passive mode, instead of an active mode (the default in PHP).

    In PHP, you switch to the passive mode by calling the ftp_pasv function after the ftp_login:

    ...
    ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
    ftp_pasv($conn_id, true) or die("Cannot switch to passive mode");
    ...
    

    See my article on FTP connection modes to understand, what the active and passive mode means, and why everyone uses the passive mode nowadays.

    0 讨论(0)
提交回复
热议问题