FTP Server | Download <?php
/**
* Php_ftp_download of function name
* Feature downloads files from FTP server
* Entry Parameters
* filename to download the file name, including the path
*/
function Php_ftp_download ($filename) {
$phpftp _host = "Ftplocalhost"; Server address
$phpftp _port = 21; Server port
$phpftp _user = "name"; User name
$phpftp _passwd = "PASSWRD"; Password
$ftp _path = dirname ($filename). "/"; Get path
$select _file = basename ($filename); Get file name
$ftp = Ftp_connect ($phpftp _host, $phpftp _port); Connecting to an FTP server
if ($ftp) {
if (Ftp_login ($ftp, $phpftp _user, $phpftp _passwd)) {//Login
if (@ftp_chdir ($ftp, $ftp _path)) {//Enter the specified path
$tmpfile = Tempnam (GETCWD (). " /"," temp "); Create a unique temporary file
if (Ftp_get ($ftp, $tmpfile, $select _file, ftp_binary)) {//download the specified file to the temp file
Ftp_quit ($FTP); Close connection
Header ("Content-type:application/octet-stream");
Header ("content-disposition:attachment; Filename= ". $select _file);
ReadFile ($tmpfile);
Unlink ($tmpfile); Delete temporary files
Exit
}
Unlink ($tmpfile);
}
}
}
Ftp_quit ($FTP);
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service