Linto's Blog

Just another WordPress.com weblog

How to download a file from server, using PHP code,FTP September 5, 2011

Filed under: Php — linodavis @ 9:23 pm

$conn_id = ftp_connect(“87.425.0″) or die(“Could not connect”);

$ftp_user_name=’dfg’;

$ftp_user_pass=’fgf!’;

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

if (($conn_id) || ($login_result))
{
$remote_file =”./public_html/uploads/”.trim($applicantName).”.txt”;
$local_fileĀ  =”uploads/”.trim($applicantName).”.txt”;
$handle = fopen($local_file, ‘w’);

if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
// echo “successfully written to $local_file\n”;
} else {
echo “There was a problem while downloading $remote_file to $local_file\n”;
}
}
else{
die(“FTP Connection Failed”);
}

ftp_close($conn_id);

Advertisement
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.