首页 > 代码库 > php的ftp类

php的ftp类

1.需求

了解php的ftp使用

2.例子

使用CI封装好的ftp类库

上传
$this->load->library(‘ftp‘);

$config[‘hostname‘] = ‘ftp.example.com‘;
$config[‘username‘] = ‘your-username‘;
$config[‘password‘] = ‘your-password‘;
$config[‘debug‘]    = TRUE;

$this->ftp->connect($config);
//路径要绝对路径
$this->ftp->upload(‘/local/path/to/myfile.html‘, ‘/public_html/myfile.html‘, ‘ascii‘, 0775);

$this->ftp->close();
下载文件列表
$this->load->library(‘ftp‘);

$config[‘hostname‘] = ‘ftp.example.com‘;
$config[‘username‘] = ‘your-username‘;
$config[‘password‘] = ‘your-password‘;
$config[‘debug‘]    = TRUE;

$this->ftp->connect($config);

$list = $this->ftp->list_files(‘/public_html/‘);

print_r($list);

$this->ftp->close();

 

参考资料:

http://codeigniter.org.cn/user_guide/libraries/ftp.html

http://php.net/manual/zh/book.ftp.php

 

php的ftp类