The following code will be connect to FTP and upload the file to server using php code.

<?

$ftp_server=”HOST NAME”;
$ftp_user_name=”USER NAME”;
$ftp_user_pass=”PASSWORD”;
$conn_id = ftp_connect($ftp_server);

// login with username and password

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

if ((!$conn_id) || (!$login_result)) {
echo “authentication failed”;
}
else
{

$source_file=”uploads/”.$fileName;
$destination_file=”/htdocs/”.$fileName;
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

}

ftp_quit($conn_id);

?>

Categories: PHP Code

2 Comments

Vishal · February 27, 2010 at 7:22 am

Hey buddy nice stuff
din knew it was soo simple and straight forward
thnx again

Dianne · February 4, 2013 at 10:16 pm

Great weblog here! Additionally your site quite a bit up fast! What web host are you the usage of? Can I am getting your affiliate hyperlink on your host? I want my site loaded up as fast as yours lol

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *