ANIL KUMAR PANIGRAHI 's Blog

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

Posted by: Anil Kumar Panigrahi in: ● July 21, 2009

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);

?>

Share on Twitter

2 Comments to "How to connect to FTP and upload file using php code?"

1 | bjrw09

16 de August de 2009 to ● 12:01 am

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

27 de February de 2010 to ● 7:22 am

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

Write Comment

About Me

  Anil Kumar Panigrahi
  Software Engineer (PHP)
  Blogger & Founder of Anil Labs
  Baruva, India

You can share with me . . .

My Own Contributions

1) First contribution for codeigniter framework ( multi language support using google translate API ). we can get files from http://github.com/nyros/codeigniter_multilanguage


2) Audio and Video Streaming using FFMpeg and PHP -complete doc file : http://www.docstoc.com/docs/8300349/Audio-and-Video-Streaming

Twitter Updates

Follow me @anil2u
  • http://www.google.co.uk/ logo is changing with mouse move . . . - posted on 07/09/2010 10:57:33
  • True enemies are real friends . . . - posted on 06/09/2010 10:15:29
  • Just watched nice movie " Madrasapattinam ". - posted on 05/09/2010 16:20:48
  • We will always be thankful to our teacher for all the hard work and efforts they have put in, for educating us.- Happy teachers Day . . . :) - posted on 05/09/2010 05:39:13
  • Working on shipping cost functionality (UPS and USPS) for oscommerce shopping cart - posted on 01/09/2010 09:40:03