Hi!

I was able to connect to another server using ftp_connect and was able to login too. But I tried to list the files in the directory but it is not working. No errors are appearing too. Any thoughts? Thanks!

Here's my code:

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");

// output $contents
var_dump($contents);

Recommended Answers

Hello,
Try using this:

<?php
    $conn_id = ftp_connect("Server");
    $login_result = ftp_login($conn_id, "Username", "Password");
    ftp_pasv($conn_id, true);

    if (($conn_id) || ($login_result)) {
        $listArray = array();
        $contentList = ftp_nlist($conn_id, ".");
        foreach ($contentList as $item) {
            array_push($listArray, array("itemname" => $item));
        }
        print_r($listArray);
    } else {
        echo "An error has occurred!";
    } …
Jump to Post

Who is your host?

Jump to Post

Are you trying to use an SSL connection?

Jump to Post

Could you show me the code your trying. Of couse with your credentials hidden.

Jump to Post

Who is your provider?

Jump to Post

All 19 Replies

Hello,
Try using this:

<?php
    $conn_id = ftp_connect("Server");
    $login_result = ftp_login($conn_id, "Username", "Password");
    ftp_pasv($conn_id, true);

    if (($conn_id) || ($login_result)) {
        $listArray = array();
        $contentList = ftp_nlist($conn_id, ".");
        foreach ($contentList as $item) {
            array_push($listArray, array("itemname" => $item));
        }
        print_r($listArray);
    } else {
        echo "An error has occurred!";
    }

    ftp_close($conn_id);
?>

I got Non SSL connections forbidden in ftp_login error.

Who is your host?

I tried to use ftp_ssl_connect and I was able to get acceptable results until ftp_login. But I cannot display the files. I also had trouble accessing the server using filezilla. But after using ftp over ssl explicit I was able to see the files. Do you think this has an effect to accessing the files?

Are you trying to use an SSL connection?

Yes, And I guess I was able to do so since ftp_ssl_connect and ftp_login returns '1'.

Could you show me the code your trying. Of couse with your credentials hidden.

Here's the code:

$conn_id = ftp_ssl_connect($ftp_server, '21') or die("Couldn't connect to $ftp_server");
$result = ftp_login($conn_id, $ftp_user, $ftp_pass);

ftp_pasv($conn_id, true);
echo ftp_pwd($conn_id)."<br/>";
$content = ftp_nlist($conn_id, ".");
var_dump($content);

ftp_close($conn_id);

I'm not sure if I'm supposed to use port 21 but in the specs this is stated: Port to allow: FTP port 21 in your firewall. So I used port 21..

Also ftp_server doesn't have ftps:// or ftp:// just plain example.com.

Who is your provider?

provider?

Like who is the company that i hosting your FTP server?

I'm not really sure because I was ust given the ftp details.
Could the problem be in the self-signedcertificate? When trying to access using filezilla, a certificate that should be accepted appears.

It could be, I'm not familiar with ftps.

But then after investigating further, it appears that I cannot connect to the right port. Now I'm having 425: Can't open data connection. error.

Have you tried just using a normal connection? (Not using ftps)

if I use simple ftp_connect, Non SSL connections forbidden error will appear.

I think it would help me better if you could tell me who is your host for your server eg. the host for my website is GoDaddy.

I was asking cmsc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.