1

谢谢你。

这是我最近尝试使用的 cURL ftp 代码,以及我得到的响应。

$str 包含 ascii 文本(一个 php 脚本)。

I have no problems at all accessing
ftp://hostingdomain/auth/
and the files within it, on a read or write basis, with an FTP client
(in the case OSX Fetch) in either passive or active mode.
In essence, I am trying to create (write) test.php within
ftp://hostingdomain/auth/
, and overwrite it if it is already there. The tmp file is being correctly created,
and deleted once the script exits.

$ch = curl_init();
$tmp = tmpfile();
fwrite($tmp, $str);
fseek($tmp, 0);

curl_setopt($ch, CURLOPT_URL, 'ftp://hostingdomain/auth/test.php');
curl_setopt($ch, CURLOPT_USERPWD, "myftpusername:myftppassword");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $tmp);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($str));

curl_exec ($ch);
$error_no = curl_errno($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close ($ch);
fclose($tmp);

if ($error_no == 0) {
$message = 'File uploaded successfully.';
} else {
$message = '<BR>File upload error: '.$error_no.' '.$error.'<BR>';
print_r ($info);
}
echo $message;

--------响应 - 脚本正在“发送”服务器上运行。

Array ( 
[url] => ftp://hostingdomain/auth/test.php
[content_type] =>
[http_code] => 227
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 16.64937
[namelookup_time] => 0.200538
[connect_time] => 0.288836
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0 
)
File upload error: 7 
couldn't connect to host

基本上我得到了一个超时,然后上面的 $info 和 $message 又回来了。ftp://hostingdomain/auth/test.php使用我的 FTP 客户端进行完全相同的传输 就可以了。

4

0 回答 0