使用PHP将txt文件从一个服务器传输到另一个服务器

时间:2013-08-09 16:07:29

标签: php curl ftp transfer

谢谢。

这是我最近尝试使用的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和$消息 回来。做完全相同的转移 我的FTP客户端ftp://hostingdomain/auth/test.php工作得很好。

0 个答案:

没有答案