在这个例子中,首先建立一个到FTP服务器的连接,接着读取一个本地文件然后以ASCII模式上传。文件的权限被设置为755。[code]$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();[/code]下面的例子从FTP服务器上获得了文件列表[code]$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();[/code]下面的例子在FTP服务器上创建了一个本地文件夹的镜像。[code]$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->mirror(‘/path/to/myfolder/’, ‘/public_html/myfolder/’);
$this->ftp->close();[/code]文章来源:http://cwiki.ossez.com/pages/viewpage.action?pageId=2392153