Download files from the ftp server

Source: Internet
Author: User
Tags download file from ftp server
& Lt ;? Php/*** function name php_ftp_download * function download file from ftp server * entry parameter * file name to be downloaded, including Path */functionphp_ftp_download ($ filename) {$ phpftp_host & quot; ftplocalhost & quot; // service...

 
 
 
 
/**
* Function name: php_ftp_download
* Function to download files from an ftp server
* Entry parameters
* Filename: the name of the file to be downloaded, 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). "/"; // Obtain the path
$ Select_file = basename ($ filename); // get the file name

$ Ftp = ftp_connect ($ phpftp_host, $ phpftp_port); // connect to the 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 a temporary file
Ftp_quit ($ ftp); // close the connection
Header ("content-type: application/octet-stream ");
Header ("content-disposition: attachment; filename =". $ select_file) // content-disposition: inline; indicates that files can be opened online!
Readfile ($ tmpfile );
Unlink ($ tmpfile); // delete a temporary file
Exit;
}
Unlink ($ tmpfile );
}
}
}
Ftp_quit ($ ftp );
}
 

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.