使用php和ftp access

时间:2016-01-20 10:18:24

标签: php ftp

我正在尝试使用从stackoverflow复制的以下代码将我的本地文件上传到服务器。我无法正确映射文件并寻求帮助。

我有两个带有$ localfile的测试用例。

  1. 使用c:使用相对路径进行映射,它会禁止文件名。
  2. 使用服务器路径进行映射。它说连接和写成功。但在服务器中,文件大小仅为0KB。
  3. 代码:

    //$local_file = 'C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\sample.csv';
    //Warning: ftp_put(): Prohibited file name: C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\sample.csv in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\test.php on line 28
    // The filename that i got the php code is test.ph
    $local_file = 'sample.csv';    
    //Connected!Successfully written to sample.csv - but not written. 
    //The file size is showing 0KB.
    $server_file = 'http://iseedtechnologies.in/sample.csv';
    
    // set up basic connection
    $conn_id = ftp_connect("iseedtechnologies.in");
    
    // login with username and password
    $login_result = ftp_login($conn_id, '****', '****');
    echo is_array(ftp_nlist($conn_id, ".")) ? 'Connected!' : 'not Connected! :(';
    ftp_pasv($conn_id, true);
    // try to download $server_file and save to $local_file
    if (ftp_put($conn_id, $local_file, $server_file, FTP_BINARY)) {
        echo "Successfully written to $local_file\n";
    } else {
        echo "There was a problem\n";
    }
    // close the connection
    ftp_close($conn_id);
    ?>
    

    工作代码(删除了http://并且有效)

    $local_file = 'sample.csv';    
    
    $server_file = 'sample.csv';
    
    // set up basic connection
    $conn_id = ftp_connect("iseedtechnologies.in");
    
    // login with username and password
    $login_result = ftp_login($conn_id, '****', '****');
    echo is_array(ftp_nlist($conn_id, ".")) ? 'Connected!' : 'not Connected! :(';
    ftp_pasv($conn_id, true);
    // try to download $server_file and save to $local_file
    if (ftp_put($conn_id, $local_file, $server_file, FTP_BINARY)) {
        echo "Successfully written to $local_file\n";
    } else {
        echo "There was a problem\n";
    }
    // close the connection
    ftp_close($conn_id);
    ?>
    

0 个答案:

没有答案