Home > PHP Code > How to connect to FTP and upload file using php code?

How to connect to FTP and upload file using php code?

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
  1. bjrw09
    August 16, 2009 at 12:01 am | #1

    Hi Anthony,

    I am trying to install by uploading the Akisment spam plugin for WordPress.

    The instructions on the Akismet site say to use ftp and upload the extracted

    akismet.php file to the wordpress blog.

    However, I don’t seem to be able to find a ftp address or a link on WordPress
    for a location to upload this plugin.

    Am I missing something here?

  1. No trackbacks yet.