简体   繁体   中英

Cannot connect to ftp through PHP

I have migrated my code from xampp to lamp recently. Since that time I have a problem with ftp_connect function and it always returns false. Here is the code:

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");

Is there any setting in PHP or apache I have to set in advanced!?

This example works for me:

$ftp_server = "SERVER IP";
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "YOUR USERNAME";
$ftp_user_pass = "YOUR PASSWORD";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$contents = ftp_nlist($conn_id, '/');
for ($i = 0 ; $i < count($contents) ; $i++)
    echo "<li>" . substr($contents[$i],1) . "</li>";
ftp_close($conn_id);

Try running this:

<?php
$c = ftp_connect('ftp.mozilla.org');
var_dump($c);

$c = ftp_connect('abcdefg');
var_dump($c);
?>

You should get this:

resource(2) of type (FTP Buffer) Warning: ftp_connect()

[function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\abc\def.php on line 5

bool(false)

Answer on : How to get error if FTP server is invalid.? . Then you will know what kind of error appears.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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