开发者

CURL with @ in username

I trying to upload a file with CURL by FTP. but I have a problem with the username, in my hosting all the FTP usernames are user@site.com so I get the following error when I try to upload:

Curl error: Couldn't resolve host 'site.com:password@site.com'

开发者_StackOverflow社区

Here is the code:

      $ftpuser = 'uploader@mysite.com';
      $ftppass = "blablabla";
      $ftppath = "mysite.com/";
      $ftpurl = "ftp://".$ftpuser.":".$ftppass."@".$ftppath;

can someone tell me how can I pass the username to solve the problem.


Two things:

  1. You should be able to get around the @ problem by using urlencode to convert the non-safe character.
  2. It would be better to use the CURLOPT_USERPWD option with curl_setopt to set the username and password pair, I believe.

So:

<?php 

$ftpuser = urlencode('uploader@mysite.com');
$ftppass = urlencode('blablabla');
$ftppath = 'mysite.com/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'ftp://' . $ftppath);
curl_setopt($ch, CURLOPT_USERPWD, $ftpuser . ':' . $ftppass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec();


can you give curl the username and password seperately, rather than all as part of the URL, that might help it understand the data more correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜