[英]php script on Windows hosting does not list ftp files (ftp_rawlist issues)
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. 我正在尝试在Windows共享主机上使用php ftp函数列出来自外部FTP服务器的一些文件,但出现了几个问题。
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.. 我首先尝试使用了几个Web应用程序,例如ajaxplorer和net2ftp,但是我感到沮丧,因此我决定制作一个非常基本的脚本进行测试。
<?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: 在我的本地主机(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)
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. 无法理解..该目录在外部ftp服务器上应为“ /”,当然还有一些文件和文件夹(2个文件夹和1个文件)。实际上,在我的MAMP安装中,它运行良好。
Hosting guys told me that the server configuration is ok. 主持人告诉我,服务器配置还可以。
use ftp_pasv($conn_id, true); 使用ftp_pasv($ conn_id,true); some ftp connections will work in passive mode only 某些ftp连接只能在被动模式下工作
Check your FTP server logs. 检查您的FTP服务器日志。 In my case, the pasv_address was set to a wrong IP address. 就我而言,pasv_address设置为错误的IP地址。
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. 在Linux服务器上,一切工作正常,但是在Windows Server(许多版本)下,我们遇到了许多问题,包括ftp_nlist()返回空数组。 This worked for us, but I don't know why! 这对我们有用,但我不知道为什么!
ftp_nlist($handler, '*');
I'm not 100% sure, but I guess, you should use $contents = ftp_rawlist($conn_id, "/");
我不确定100%,但是我想,您应该使用$contents = ftp_rawlist($conn_id, "/");
instead of $contents = ftp_rawlist($conn_id, ".");
而不是$contents = ftp_rawlist($conn_id, ".");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.