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:
- You should be able to get around the
@
problem by usingurlencode
to convert the non-safe character. - It would be better to use the
CURLOPT_USERPWD
option withcurl_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.
精彩评论