无法使用 PHP 连接 FTP 服务器,ftp_connect()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6536435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:40:33  来源:igfitidea点击:

Cannot connect with FTP server with PHP , ftp_connect()

phpftp

提问by Quazi Farhan

I was trying to connect with ftp server using ftp_connect() function of PHP as shown below:

我试图使用 PHP 的 ftp_connect() 函数连接 ftp 服务器,如下所示:

<?php

$ftp_server = "http://ftp.mozilla.org/pub/mozilla.org/";

$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

?>

But it returns this error:

但它返回此错误:

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\wamp\www\ftp2.php on line 6

警告:ftp_connect() [function.ftp-connect]:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。在 D:\wamp\www\ftp2.php 第 6 行

Although this is a very common type of error, I still cannot find any solution. Can anyone provide some possible solutions?

尽管这是一种非常常见的错误类型,但我仍然找不到任何解决方案。谁能提供一些可能的解决方案?

Thank you for your time.

感谢您的时间。

回答by Michael Berkowski

You must supply only the ftp server hostname, rather than the hostname and directory path, and the irrelevant http://since this is an FTP connection.

您必须只提供 ftp 服务器主机名,而不是主机名和目录路径,http://因为这是一个 FTP 连接,所以不相关。

$ftp_server = "ftp.mozilla.org";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// Then chdir to the correct directory:
ftp_chdir($conn_id, "/pub/mozilla.org");

See the full documentation of PHP's FTP functions.

请参阅PHP 的 FTP 函数完整文档

回答by Pekka

Get rid of the http://, it is not part of the server address.

去掉http://,它不是服务器地址的一部分。