I recently came across an issue when implementing an FTP file upload function via CURL. Because my FTP username was ‘alex@mydomain.com’ I had a hard time connecting because the code would think everything after the @ sign was part of the host – which it obviously wasn’t.

Doing a bit of Google searching I found other newbie coders also had this issue, so here is the solution I created if anyone happens to come here from Google:

$ch = curl_init();
$target3 = "C:/www/upload/".$target2;
$fp = f*open($target3, 'r');
$ftpurl = "ftp.servername.com/";
$ftpusr = urlencode("user@mydomain.com");
$ftppass = "mycrazypassword";
curl_setopt($ch, CURLOPT_URL, 'ftp://'.$ftpusr.':'.$ftppass.'@'.$ftpurl.$target3);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($target3));

**Note: for the fopen function, I had to list it as f*open because it would not let me post it for some reason.

Popularity: 78% [?]

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Mixx
  • Google Bookmarks
  • co.mments
  • eKudos
  • Furl
  • Kirtsy
  • LinkedIn
  • Live
  • MisterWong
  • Print
  • Reddit
  • Slashdot
  • Spurl
  • Technorati
  • TwitThis
  • YahooMyWeb

What did you think about this post? Leave a comment below!