使用PHP从ftp服务器下载文件 [英] Download files from ftp server in PHP

查看:457
本文介绍了使用PHP从ftp服务器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下格式的php代码从ftp服务器下载文件.

I am using the following format in php code to download files from ftp server.

file_put_contents(
            $filePath.$fileName, file_get_contents(
                ftp://username:password@server_name/folder_name/xyz#123.csv.zip
            )
);    

文件名包含#",我收到550错误.如何避免错误.另外,在FTP上执行不同操作的最佳PHP类是什么?

I am getting an 550 error as the file name contains '#'. How to avoid the error. Also what is the best PHP class to do different operations on FTP ?

推荐答案

使用此

<?php

// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($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);

?>

这篇关于使用PHP从ftp服务器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆