Windows 主机上的 php 脚本不列出 ftp 文件(ftp_rawlist 问题)

发布于 2025-01-01 01:48:01 字数 1262 浏览 0 评论 0原文

我正在尝试在 Windows 共享主机上使用 php ftp 函数列出来自外部 FTP 服务器的一些文件,但遇到了几个问题。

我首先尝试使用 ajaxplorer 和 net2ftp 等几个 Web 应用程序,但我感到沮丧,我决定制作一个非常基本的脚本进行测试。

<?php   
$ftp_server = "alinuxftpserver";
$ftp_user = "user";
$ftp_pass = "pass";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// change temp folder (windows)
putenv("TMP=D://inetpub//webs//domain//net2ftp//tmp");
echo getenv('TMP'); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) 
{
    echo "Connected as $ftp_user@$ftp_server\n";
} 
else 
{
    echo "Couldn't connect as $ftp_user@$ftp_server\n";
}

if(ftp_pasv( $conn_id, true )) 
      echo "Passive mode, it worked<br/>"; 
    else 
      echo "Passive mode, it didn't work<br/>";

$contents = ftp_rawlist($conn_id, ".");
var_dump($contents);

ftp_close($conn_id);  

die;

?>

在我的本地主机(linux)上它返回一个数组,而在托管它的 Windows 上返回:

Warning: ftp_rawlist() [function.ftp-rawlist]: php_connect_nonb() failed: No such file or directory (2) in D:\inetpub\webs\domain\ftp.php on line 26
bool(false)

无法理解..目录应该是外部 ftp 服务器上的“/”,当然还有一些文件和文件。文件夹(2 个文件夹和 1 个文件).. 事实上,在我的 MAMP 安装中它运行良好。

托管人员告诉我服务器配置没问题。

I'm trying to list some files from an external FTP server using php ftp functions on a Windows shared hosting, but I'm having several problems.

I firstly tried with a couple of web applications like ajaxplorer and net2ftp, but I got frustrated and I decided to make a very basic script for testing..

<?php   
$ftp_server = "alinuxftpserver";
$ftp_user = "user";
$ftp_pass = "pass";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// change temp folder (windows)
putenv("TMP=D://inetpub//webs//domain//net2ftp//tmp");
echo getenv('TMP'); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) 
{
    echo "Connected as $ftp_user@$ftp_server\n";
} 
else 
{
    echo "Couldn't connect as $ftp_user@$ftp_server\n";
}

if(ftp_pasv( $conn_id, true )) 
      echo "Passive mode, it worked<br/>"; 
    else 
      echo "Passive mode, it didn't work<br/>";

$contents = ftp_rawlist($conn_id, ".");
var_dump($contents);

ftp_close($conn_id);  

die;

?>

On my localhost (linux) it returns an array, while on the windows hosting it returns:

Warning: ftp_rawlist() [function.ftp-rawlist]: php_connect_nonb() failed: No such file or directory (2) in D:\inetpub\webs\domain\ftp.php on line 26
bool(false)

Can't understand.. the directory should be "/" on the external ftp server and of course there are some files & folders (2 folders and 1 file).. In fact on my MAMP installation it works well.

Hosting guys told me that the server configuration is ok.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

念﹏祤嫣 2025-01-08 01:48:01

使用 ftp_pasv($conn_id, true);某些 ftp 连接只能在被动模式下工作

use ftp_pasv($conn_id, true); some ftp connections will work in passive mode only

鸩远一方 2025-01-08 01:48:01

我不是 100% 确定,但我想,你应该使用 $contents = ftp_rawlist($conn_id, "/");
而不是 $contents = ftp_rawlist($conn_id, ".");

I'm not 100% sure, but I guess, you should use $contents = ftp_rawlist($conn_id, "/");
instead of $contents = ftp_rawlist($conn_id, ".");

漫漫岁月 2025-01-08 01:48:01

检查您的 FTP 服务器日志。就我而言,pasv_address 设置为错误的 IP 地址。

Check your FTP server logs. In my case, the pasv_address was set to a wrong IP address.

爱殇璃 2025-01-08 01:48:01

迟到总比不到好……我也遇到了同样的问题。对于 Linux 服务器,一切都运行良好,但对于 Windows Server(许多版本),我们遇到了很多问题,包括 ftp_nlist() 返回空数组。这对我们有用,但我不知道为什么!

ftp_nlist($handler, '*');

Better late than never... I had the same problem. With a Linux server everything worked great, but with Windows Server (many versions) we had many problems, including with ftp_nlist() returning an empty array. This worked for us, but I don't know why!

ftp_nlist($handler, '*');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文