Home > Backend Development > PHP Tutorial > Simple example of using ftp to download files in php

Simple example of using ftp to download files in php

WBOY
Release: 2016-07-25 09:00:23
Original
1307 people have browsed it
Let me give you an example of using PHP ftp function to download files, and practice the usage of FTP function in PHP for the reference of beginners.

The code is as follows:

<?php
/**
 * ftp下载文件
 * site bbs.it-home.org
*/
function downfromftp($file){
//连接服务器
$conn_id = ftp_connect(“123.xxx.xxx.99”); //远程FTP的IP地址
//登陆
$login_result = ftp_login($conn_id, “1″, “kkk”);
//更改下载目录
if($login_result){
  $res=ftp_chdir($conn_id, “anony_ftp”);
  if(!$res){
    exit(‘更改目录失败’);
}
}
// 下载文件
$local_file = ‘down/’.$file;
$server_file = $file;
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
   ftp_close($conn_id);
   fclose($fp);
   return true;
} else {
   ftp_close($conn_id);
   fclose($fp);
   return false;
}
}
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template