PHP的FTP不工作在Amazon Linux的EC2实例? [英] PHP's FTP isn't working on Amazon linux EC2 instance?
问题描述
我成立了一个m1.large EC2实例,并希望用它来下载日志掀起了CDN的服务器。我有code工作就好在我的Ubuntu的笔记本电脑,但一旦上传到ftp_rawlist()函数停止工作的服务器。至于我可以告诉code仍是登录到FTP服务器,但rawlist没有返回任何文件。
I set up a m1.large EC2 instance and want to use it to download logs off a cdn's server. I had the code working just fine on my ubuntu laptop but once uploaded to the server the ftp_rawlist() function stopped working. As far as i can tell the code is still logging into the ftp server but rawlist isn't returning any files.
下面是示例code:
<?php
$FTP_USERNAME = 'username';
$FTP_PASSWORD = 'pass';
$FTP_SERVER = 'cdn.server';
$FTP_LOGDIR = 'logs';
$conn_id = ftp_connect($FTP_SERVER) or die('Couldn\'t connect to '.$FTP_SERVER);
if(!ftp_login($conn_id, $FTP_USERNAME, $FTP_PASSWORD)) {
die('Couldn\'t connect as '.$FTP_USERNAME);
}
ftp_chdir($conn_id, $FTP_LOGDIR);
$rawlist = ftp_rawlist($conn_id, '.');
ftp_close($conn_id);
var_dump($rawlist);
?>
和输出是这样的:
bool(false)
尽管我知道目录不是空的。
even though i know the directory isn't empty.
在设置服务器,这些都是我用来安装所有的命令:
When setting up the server these are the commands i used to install everything:
sudo yum install php
sudo yum install php-mysql
sudo yum install php-pear
sudo pear channel-discover pear.amazonwebservices.com
sudo pear install aws/sdk
我甚至打开所有的端口安全组,但即使再输出仍然布尔(假)。和PHP -i显示,启用FTP。
I even opened all the ports for the security group but even then the output was still bool(false). And php -i shows that ftp is enabled.
任何帮助将是很大的AP preciated,我一直在货架我的脑子整天都试图弄清楚这一点。
Any help would be greatly appreciated, i have been racking my brain all day trying to figure this out.
推荐答案
所需在被动模式下运行。
Needed to run it in passive mode
ftp_pasv($conn_id, true);
这篇关于PHP的FTP不工作在Amazon Linux的EC2实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!