. */ /** * Class FTP * @author Brian Shaw * @uses Connects to an ftp server and uploads/downloads the specified file. */ class ftp { var $host; var $port=21; var $timeout=30; var $user; var $pass; var $base; var $result; var $error; function connect() { if (!isset($this->host)) {$this->error='no host';return false;} $this->result=ftp_connect($this->host,$this->port,$this->timeout); if (is_resource($this->result)!=true) {$this->error='bad host';return false;} if ($this->login()!=1) {$this->error='failed login';return false;} $this->error=0; } function login() { if ($this->error>0||empty($this->user)||empty($this->pass)) {$this->error='username or password was not set';return false;} return ftp_login($this->result, $this->user, $this->pass); } function disconnect() { return ftp_close($this->result); } function upload($local_file,$remote_file) { if (is_resource($this->result)!=true) {$this->error='download failed';return false;} return ftp_put($this->result,$this->base.$remote_file,$local_file,FTP_BINARY); } function download($local_file,$remote_file) { if (is_resource($this->result)!=true) {$this->error='download failed';return false;} return ftp_get($this->result,$local_file,$this->base.$remote_file,FTP_BINARY); } }; $ftp=&new ftp; $ftp->host=''; $ftp->port=21; $ftp->timeout=30; $ftp->base='/web/'; $ftp->user=''; $ftp->pass=''; $ftp->connect(); //$ftp->download('index.html','index.html'); $ftp->upload('test.txt','test.txt'); $ftp->disconnect(); ?>