本文介绍了通过FTP上传PHP - ftp_put()我不会打开x.x.x.x的连接(仅限于y.y.y.y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用一台主机通过FTP将内容上传到另一台主机。



我不会打开与172.xxx的连接.xxx.xxx(仅限于54.xxx.xxx.xxx)甚至不相关,因为我没有连接到该主机。这是承载脚本的服务器的IP地址。

  $ conn_id = ftp_connect('50 .xxx.xxx.xxx' ); 
ftp_pasv($ conn_id,true);

$ login_result = ftp_login($ conn_id,'user','pass');

$ file =http://example.com/filelocation.swf;

if(ftp_put($ conn_id,test.swf,$ file,FTP_BINARY)){
echo'File Uploaded';
}
else {
echo'上传时出现问题';



此错误中的IP地址,不会转到我尝试连接的服务器。 ftp_login 连接并且没有问题。 (我甚至不希望它连接到这些IP地址,为什么它甚至会这么想?)

我可以使用 ftp_mkdir 在服务器上添加一个目录。但是,当我使用 ftp_put 时,会引发该错误。

解决方案

错误消息实际上非常相关。

它是Pure-FTPd对 PORT 命令的错误响应,当客户端要求服务器打开与客户端不同的IP地址的数据连接(如服务器所见)。因此,这是服务器发送的远程错误消息,而不是PHP产生的本地错误消息。



这个问题通常是由客户端只知道其本地IP地址,而不是外部IP地址。






现在,问题是为什么PHP使用 PORT ftp_pasv )。



显然是因为你在登录前调用 ftp_pasv 因此,服务器拒绝 PASV call with:

不幸的是,PHP不会传播来自 PASV 调用的错误消息。它静静地回落到默认的活动模式。你可以通过它的返回值来告诉调用失败(你不检查)。






只要移动<$ c在 ftp_login 之后调用$ c> ftp_pasv 。

  $ conn_id = ftp_connect('50 .xx.xx.xx'); 

ftp_login($ conn_id,'user','pass');

ftp_pasv($ conn_id,true);

清楚地表明了它:






当然,您应该做更好的错误检查。


I'm trying to use one host to upload content to another via FTP.

The "I won't open a connection to 172.xxx.xxx.xxx (only to 54.xxx.xxx.xxx)" is not even relevant because I am not connecting to that host. That's the IP address to the server that is hosting the script. But not to the server that is being accessed via FTP.

$conn_id = ftp_connect('50.xxx.xxx.xxx');
ftp_pasv($conn_id, true);

$login_result = ftp_login($conn_id, 'user', 'pass');

$file = "http://example.com/filelocation.swf";

if (ftp_put($conn_id, "test.swf", $file, FTP_BINARY)) {
    echo 'File Uploaded';
}
else {
    echo 'Problem with uploading';
}

The IP addresses within this error, does not go to the server I am trying to connect to. The ftp_login connects and no issues. ( I don't even want it to make a connection to those IP addresses anyways, so why does it even think that?)

I can use ftp_mkdir to add a directory on the server. However, when I use ftp_put, it throws that error.

解决方案

The error message is actually very relevant.

It's Pure-FTPd error response to PORT command, when the client is asking the server to open a data connection to an IP address different to that of the client (as the server sees it). So it's a remote error message sent by the server, not a local error message produced by PHP.

The problem is typically caused by the client knowing only its local IP address, not the external IP address.


Now, the question is why PHP uses PORT, when you asked it to connect using passive mode (ftp_pasv).

It's clearly because you call ftp_pasv before even logging in.

So the server rejects the PASV call with:

Unfortunately the PHP does not propagate error messages from PASV call. And it silently falls back to the default active mode. You can tell the call failed by its return value (that you do not check).


Just move the ftp_pasv call after the ftp_login.

$conn_id = ftp_connect('50.xx.xx.xx');

ftp_login($conn_id, 'user', 'pass');

ftp_pasv($conn_id, true);

The documentation clearly suggests it:


And of course, you should do a better error checking.

这篇关于通过FTP上传PHP - ftp_put()我不会打开x.x.x.x的连接(仅限于y.y.y.y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:54