doukong1391 2016-01-20 10:18
浏览 77

使用php和ftp访问将本地上传到服务器

I am trying to upload my local file to server with the following code copied from stackoverflow. I couldnt map the files right and looking for assistance.

I got two test cases with $localfile.

  1. mapping with relative path using c:, it throws filename prohibited.
  2. mapping with server path. it says connected and written successfully. But in server the file size is 0KB only.

The code:

//$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
";
} else {
    echo "There was a problem
";
}
// close the connection
ftp_close($conn_id);
?>

Working code (Removed the http:// and it worked)

$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
";
} else {
    echo "There was a problem
";
}
// close the connection
ftp_close($conn_id);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度