0

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);

Edited by cmsc

3
Contributors
19
Replies
80
Views
4 Years
Discussion Span
Last Post by joshl_1995
0

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);
?>
0

I got Non SSL connections forbidden in ftp_login error.

0

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?

0

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

0

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.

0

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.

0

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.

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.