ftp_get:非法 PORT 命令 [英] ftp_get: Illegal PORT command

查看:21
本文介绍了ftp_get:非法 PORT 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在localhost"上,我尝试从 FTP 服务器获取文件,并且成功创建了本地文件.但是当我在 Ubuntu 服务器中尝试时,它显示存在问题并且文件没有下载到服务器中.这是代码.并在此位置创建代码文件 /var/www/html/

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 and file is not downloading into server. Here is the code. And code file created in this location /var/www/html/

<?php
$local_file = 'whdfcleads.csv';
$server_file = 'hdfc/hdfc_leads.csv';
$ftp_server="*********";
$conn_id = ftp_connect($ftp_server)or die("Couldn't connect to $ftp_server");
$ftp_user_name="*****";
$ftp_user_pass="******";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
  echo "Successfully written to $local_file
";
}
else{
  echo "There was a problem
";
}
ftp_close($conn_id);
?>

请帮我解决这个问题,在本地主机上它工作正常,但在 Ubuntu 服务器本地文件没有创建/下载.

Please help me to solve this issue, in local host it's working fine but in Ubuntu server local file not creating/downloading.

错误是

Array (
    [type] => 2
    [message] => ftp_get(): Illegal PORT command
    [file] => /var/www/html/wftp.php
    [line] => 15
)

推荐答案

"Illegal PORT command"是ProFTPD服务器收到PORT命令时发出的消息IP 地址无效.

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

当客户端位于 NAT 后面并向服务器报告其内部 IP 地址时,通常会发生这种情况,但不知道服务器无法返回该 IP 地址.

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.

最简单(通常也是正确的)解决方案是使用 FTP 被动模式,而不是主动模式(PHP 中的默认设置).

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

在 PHP 中,您可以通过调用 ftp_login之后的>ftp_pasv函数:

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");
...

请参阅我的 关于 FTP 连接模式的文章,了解主动和被动模式的含义,以及为什么现在每个人都使用被动模式.

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

这篇关于ftp_get:非法 PORT 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆