XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
ftpclient.php
Go to the documentation of this file.
1 <?php
2 // $Id: modules.php 965 2012-05-28 03:18:09Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
12 {
13  private $server = '';
14  private $port = 21;
15  private $uname = '';
16  private $pass = '';
17  // Almacena el manejador ftp
18  private $connection = '';
19 
27  public function __construct($server,$port=21,$uname='',$pass=''){
28 
29  $this->server = $server;
30  $this->port = $port;
31  $this->uname = $uname;
32  $this->pass = $pass;
33 
34  }
35 
40  public function connect($ssl = false, $timeout = 90){
41  $this->connection = $ssl ? ftp_ssl_connect($this->server, $this->port, $timeout) : ftp_connect($this->server, $this->port, $timeout);
42  if (!ftp_login($this->connection, $this->uname, $this->pass)){
43  return false;
44  } else {
45  return true;
46  }
47  }
48 
53  public function pasv($bool = true){
54  ftp_pasv($this->connection, $bool);
55  }
56 
61  public function pwd(){
62  return ftp_pwd($this->connection);
63  }
64 
70  public function chdir($dir){
71  return ftp_chdir($this->connection, $dir);
72  }
73 
79  public function delete($ruta){
80  return ftp_delete($this->connection, $ruta);
81  }
82 
89  public function chmod($mode, $ruta){
90  return ftp_chmod($this->connection, intval($mode), $ruta);
91  }
92 
101  public function get($local, $remote, $mode = FTP_ASCII, $pos = 0){
102  return ftp_get($this->connection, $local, $remote, $mode, $pos);
103  }
104 
110  public function mtime($ruta){
111  return ftp_mdtm($this->connection, $ruta);
112  }
113 
119  public function mkdir($dir){
120  return ftp_mkdir($this->connection, $dir);
121  }
122 
128  public function nlist($dir){
129  return ftp_nlist($this->connection, $dir);
130  }
131 
140  public function put($remote, $local, $mode = FTP_ASCII, $pos = 0){
141  return ftp_put($this->connection, $remote, $local, $mode, $pos);
142  }
143 
150  public function rawlist($dir, $mode = false){
151  return ftp_rawlist($this->connection, $dir, $mode);
152  }
153 
160  public function rename($old, $new){
161  return ftp_rename($this->connection, $old, $new);
162  }
163 
169  public function rmdir($dir){
170  return ftp_rmdir($this->connection, $dir);
171  }
172 
178  public function size($file){
179  return ftp_size($this->connection, $file);
180  }
181 
182  public function systype(){
183  return ftp_systype($this->connection);
184  }
185 
191  public function isDir($dir){
192  $current = $this->pwd();
193  if ($this->chdir($dir)){
194  $this->chdir($current);
195  return true;
196  } else {
197  return false;
198  }
199  }
200 
204  public function close(){
205  ftp_close($this->connection);
206  }
207 }