简体   繁体   English

PHP的FTP无法在Amazon linux EC2实例上运行?

[英]PHP's FTP isn't working on Amazon linux EC2 instance?

I set up a m1.large EC2 instance and want to use it to download logs off a cdn's server. 我设置了一个m1.large EC2实例,并希望用它从cdn的服务器上下载日志。 I had the code working just fine on my ubuntu laptop but once uploaded to the server the ftp_rawlist() function stopped working. 我的代码在我的ubuntu笔记本电脑上运行得很好但是一旦上传到服务器,ftp_rawlist()函数就停止了工作。 As far as i can tell the code is still logging into the ftp server but rawlist isn't returning any files. 据我所知,代码仍然登录到ftp服务器,但rawlist没有返回任何文件。

here is the sample 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);
?>

and the output is this: 输出是这样的:

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

I even opened all the ports for the security group but even then the output was still bool(false). 我甚至打开了安全组的所有端口,但即便如此,输出仍然是bool(false)。 And php -i shows that ftp is enabled. 而php -i显示ftp已启用。

Any help would be greatly appreciated, i have been racking my brain all day trying to figure this out. 任何帮助都将非常感激,我一整天都在绞尽脑汁试图解决这个问题。

需要以被动模式运行它

ftp_pasv($conn_id, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM