Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

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). And php -i shows that ftp is enabled.

Any help would be greatly appreciated, i have been racking my brain all day trying to figure this out.

share|improve this question
    
Duplicate of stackoverflow.com/questions/8424125/… –  Eric Hammond Dec 8 '11 at 1:44

1 Answer 1

up vote 1 down vote accepted

Needed to run it in passive mode

ftp_pasv($conn_id, true);

share|improve this answer
    
That or I was gonna suggest you might need to open up your Security Group to allow ftp-data (20/tcp) which is needed if you're not using PASV FTP connections. I believe the server initiates the connection back on port 20/tcp after the client has connected on port 21/tcp and the firewall created by the Security Group would reject that unless allowed. –  Jeremy Bouse Dec 8 '11 at 19:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.