How to connect to FTP and upload file using php code?
Saturday, April 3, 2010 3:15Posted in category PHP
No Comments
How to connect to FTP and upload file using php code?
The following code will connect to the ftp and upload the file to the server using php code
<?php
$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);
?>
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.