无法使用php将文件上传到ftp服务器

时间:2009-12-09 17:06:32

标签: php file-upload ftp

我正在尝试使用php将文件上传到FTP服务器,但它没有上传。

代码:

   $response =<<<RESPONSE
    <cdm:Response>
    <cdm:header exportTime="{$export_time}" baseVersion="{$baseline_snapshot_id}" version="{$this->snapshot_id}">
            <cdm:countryCode>{$this->domain}</cdm:countryCode>
            <cdm:description>{$description}</cdm:description>
            <cdm:environment>{$destination}</cdm:environment>
            <cdm:name>{$name}</cdm:name>
    </cdm:header>
    <cdm:Status>{$this->status}</cdm:Status>
    </cdm:Response>
    RESPONSE;

   $handler = fopen($log_file_name, 'w');
   fwrite($handler, $response);
   fclose($handler);

   $server = "adoshi.dev.com";
   $ftp_user_name = "adoshi";
   $ftp_user_pass = "*******";
   #$source = $handler;
   $mode = "FTP_ASCII";
   $dest = "/home/adoshi/ftp_folder";
   $connection = ftp_connect($server);
   $login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
   if (!$connection || !$login) { die('Connection attempt failed!'); }
   $upload = ftp_nb_put($connection, $dest, $handler, $mode);
   if (!$upload) { echo 'FTP upload failed!'; }
   ftp_close($connection);

我已经提供了所有登录凭据,所以仍然想知道它为什么不使用php上传到远程服务器。

任何指导都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

你不需要创建一个文件处理程序来上传它们你只需要该文件的路径和这样的文件名

$destFile= "test.htm";
$lokal_file = "test.htm";
$upload = ftp_put ($connection_id, $destFile, $lokal_file, FTP_ASCII);