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

in PHP Code / 3 Comments

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”;
$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”;

$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);




With more than 8 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Discussion 3 Comments

  1. bjrw09

    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?

  2. Vishal

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

  3. Dianne

    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

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>