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

使用PHP将txt文件从一台服务器传输到另一台服务器,php,curl,ftp,transfer,Php,Curl,Ftp,Transfer,多谢各位 下面是我最近尝试使用的cURL ftp代码,以及我得到的响应 $str包含ascii文本(一个php脚本) 基本上,我得到了一个超时,然后是上面的$info和$message 回来了。做完全相同的转换到 ftp://hostingdomain/auth/test.php我的FTP客户端运行得很好。如果不知道您(使用代码)尝试了什么,以及您不了解的问题是什么,就无法帮助您。这不是一个我们将为您编写代码的站点。这就是你学习的地方。如果这不是你想要的,那么我建议请一位顾问。你认为我为什么来这

多谢各位

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

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

基本上,我得到了一个超时,然后是上面的$info和$message 回来了。做完全相同的转换到
ftp://hostingdomain/auth/test.php
我的FTP客户端运行得很好。

如果不知道您(使用代码)尝试了什么,以及您不了解的问题是什么,就无法帮助您。这不是一个我们将为您编写代码的站点。这就是你学习的地方。如果这不是你想要的,那么我建议请一位顾问。你认为我为什么来这里?当然要学习——这就是问题所在!我可以向您发布许多我尝试过但遇到问题的代码行-主要是一些模糊的问题,这些问题没有为我提供有用的错误输出。这一定是一个共同的需求,因此我的请求不是让您编写代码(我没有要求!),而是分享任何有用的东西。不管怎么说,我相信还有很多其他乐于助人的人可以帮助我……而不是因为我现在在这里得到的东西而推迟!你不应该被推迟。。。我正试图向你解释这个问题出了什么问题,因为它已经发布了。cURL和FTP正是您应该使用的解决方案。这是一个共同的需要。如果你不能解释这些问题是什么,我们也帮不了你。谢谢。下面是我最近尝试使用的cURL ftp代码,以及我得到的响应$str包含ascii文本(一个php脚本)。使用FTP客户端(在OSX Fetch的情况下)以被动或主动模式以读或写的方式访问文件和其中的文件,我没有任何问题。本质上,我正在尝试在中创建(编写)test.php,如果已经存在,则覆盖它。正在正确创建tmp文件,并在脚本退出后将其删除。$ch=curl_init()$tmp=tmpfile();fwrite($tmp,$str);fseek($tmp,0);curl_setopt($ch,CURLOPT_URL');curl_setopt($ch,CURLOPT_USERPWD,“myftpusername:myftppassword”);curl_setopt($ch,CURLOPT_VERBOSE,1);curl_setopt($ch,CURLOPT_上传,1);curl_setopt($ch,CURLOPT_infle,$tmp);卷曲设置($ch,卷曲填充,strlen($str));curl_exec($ch);
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