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

查看:269
本文介绍了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\n";
}
else{
  echo "There was a problem\n";
}
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
)

推荐答案

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

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之后的功能> :

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天全站免登陆