【问题标题】:php ftp upload problemphp ftp上传问题
【发布时间】:2011-02-28 11:25:09
【问题描述】:

我正在尝试编写一个将文件上传到 FTP 服务器的小型 php 函数,但我一直收到相同的错误,但我无法通过谷歌搜索问题找到任何解决方法,我希望你们能在这里帮助我...

我得到的错误是:Warning: ftp_put() [function.ftp-put]: Unable to build data connection: No route to host in.

文件是在 FTP 服务器上创建的,但它是零字节。

代码如下:

<?php
$file = "test.dat";

$ftp_server="ftp.server.com";
$ftp_user = "myname";
$ftp_pass = "mypass";
$destination_file = "test.dat";


$cid=ftp_connect($ftp_server);
if(!$cid) {
    exit("Could not connect to server: $ftp_server\n");
}

$login_result = ftp_login($cid, $ftp_user, $ftp_pass);
if (!$login_result) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user";
    exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user";
}

$upload = ftp_put($cid, $destination_file, $file, FTP_BINARY);
if (!$upload) {
    echo "Failed upload for $source_file to $ftp_server as $destination_file<br>";
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}

ftp_close($cid);
?>

【问题讨论】:

    标签: php upload ftp


    【解决方案1】:

    我忘记将 FTP 设置为被动模式:

    ftp_pasv($cid, true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      相关资源
      最近更新 更多