I have a little problem with this pice of code. The script connects, but it wont give me the folders that are located in root ... i am missing something?
$ftp_server = "ftp.something.com";
$ftp_user = "user";
$ftp_pass = "pass";
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass))
{
echo "Connected as $ftp_user@$ftp_server\n";
}
else
{
echo "Couldn't connect as $ftp_user@$ftp_server\n";
}
$contents = ftp_nlist($conn_id, ".");
var_dump($contents);
ftp_close($conn_id);
die;
It outputs
Connected as $ftp_user@$ftp_server;
and
boolean false
Why it won't list the files?
i could solve this very fast with
file_exists("ftp//user:pass@host.com")
... but the easy part is not what im looking for, i would not learn anything
I would also just suggest confirming who and where you are to make sure that permissions and the actual results you expect are true (a little sanity check once in a while is healthy).
and after you connect as user then
if you can do these things from command line as this user and list contents of the directory then you should be well on your way.
ftp_nlist()
returnsfalse
when an error occurs. I'm guessing you need to use passive transfer:Generell, I'd recommend troubleshooting this by using a a CLI tool like
ftp
or a GUI-client like Filezilla. The log/output is very, very helpful.HTH
Don't be panic. Its easy to solve. After
ftp_login()
just use the code given in the below.This code solved my problem.