Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ftp_get works on localhost, but not on production server

Tags:

php

ftp

I am using ftp_get to fetch a file from another ftp server.

My code works perfectly on my local WAMP server, but when I apply it to my actual web hosting, the connection fails.

$conn = ftp_connect('ftp.server.com') or die('Could not connect');
ftp_login($conn,'myusername','mypassword');
$local_file = 'new/two.txt';
$remote_file = 'games/minecraft/craftbukkit/plugins/VisitCounter/config.yml';
$get = ftp_get($conn,$local_file,$remote_file,FTP_ASCII);

if ($get){

    echo 'Connection Successful';
} else{

    echo 'Connection failure';
}

exec($get);
ftp_close($conn);

I'm thinking that something required to establish a ftp connection must be disabled on my web server.

Can any of you assist?

Thanks,

Jared

like image 990
JazzyP Avatar asked Oct 26 '25 14:10

JazzyP


1 Answers

Your server is not in a passive mode,You just need to turns on passive mode of your server using the php function as :-

$conn_id = ftp_connect($ftp_server);   

// login with username and password

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

// turn passive mode on

$ps = ftp_pasv($conn_id, true);

Hope it will work.

like image 176
Vishnu Choudhary Avatar answered Oct 29 '25 04:10

Vishnu Choudhary



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!