Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with connecting ftp through php

Tags:

php

ftp

I'm trying to connect to my server using php script to upload some files...

But it doesn't connect...

I dont know what is the error...

I'm sure that ftp is enable, i checked it through php_info()

What may be the error...

<?php
error_reporting(E_ALL); 
$ftp_server = "server.com";  //address of ftp server (leave out ftp://)
$ftp_user_name = "Username"; // Username
$ftp_user_pass = "Password";   // Password

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

$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass);

if ($login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass)) {
    echo "Connected as ,$ftp_user_name,$ftp_user_pass \n";
} else {
    echo "Couldn't connect \n";
}
.....
.....
....
....
ftp_close($conn_id); // close the FTP stream
?>
like image 567
Vijay Avatar asked Sep 01 '26 20:09

Vijay


1 Answers

maybe you have to turn on the passive mode by doing:

ftp_pasv($conn_id, true);

directly after your ftp_login

PS: why do you do a double login? write

$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass);

if ($login_result) {

instead of

$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass);

if ($login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass)) {
like image 120
oezi Avatar answered Sep 03 '26 10:09

oezi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!