Search code examples
phpamazon-web-servicesamazon-ec2ftp

PHP ftp connection to Amazon EC2 Instance


Hi I have been struggling on this for one day. My ftp connection through putty is working file where i am passing public DNS and then upload .pem key for password. But when i am trying to do so through PHP it is not able to connect. Any help would be highly appreciated. My PHP Code is:

$server='AMAZON EC2 Public DNS';
$username='root';
$password='**i copy pasted key from .pem file**';

try {

    $con = ftp_connect($server);
    ftp_pasv($con, true);
    if (false === $con) {
        throw new Exception('Unable to connect');
    }

    $loggedIn = ftp_login($con,  $username,  $password);
    if (true === $loggedIn) {
        echo 'Success!';
    } else {
        throw new Exception('Unable to log in');
    }


    ftp_close($con);
} catch (Exception $e) {
    echo "Failure: " . $e->getMessage();
}

Solution

  • Thanks everyone for your effort. I had solved this using SSH Connection to Amazon Ec2