Public Member Functions | |
open (array $args=array()) | |
close () | |
mkdir ($dir, $mode=0777, $recursive=true) | |
rmdir ($dir, $recursive=false) | |
pwd () | |
cd ($dir) | |
read ($filename, $dest=null) | |
write ($filename, $src, $mode=null) | |
rm ($filename) | |
mv ($src, $dest) | |
chmod ($filename, $mode) | |
ls ($grep=null) | |
Public Attributes | |
const | ERROR_EMPTY_HOST = 1 |
const | ERROR_INVALID_CONNECTION = 2 |
const | ERROR_INVALID_LOGIN = 3 |
const | ERROR_INVALID_PATH = 4 |
const | ERROR_INVALID_MODE = 5 |
const | ERROR_INVALID_DESTINATION = 6 |
const | ERROR_INVALID_SOURCE = 7 |
Protected Member Functions | |
_tmpFilename ($new=false) | |
Protected Attributes | |
$_config | |
$_conn | |
$_error | |
$_tmpFilename |
Definition at line 35 of file Ftp.php.
_tmpFilename | ( | $ | new = false |
) | [protected] |
Definition at line 320 of file Ftp.php.
00321 { 00322 if ($new || !$this->_tmpFilename) { 00323 $this->_tmpFilename = tempnam( md5(uniqid(rand(), TRUE)), '' ); 00324 } 00325 return $this->_tmpFilename; 00326 }
cd | ( | $ | dir | ) |
Change current working directory
string | $dir |
Implements Varien_Io_Interface.
Definition at line 201 of file Ftp.php.
chmod | ( | $ | filename, | |
$ | mode | |||
) |
Change mode of a directory or a file
string | $filename | |
int | $mode |
Implements Varien_Io_Interface.
Definition at line 300 of file Ftp.php.
close | ( | ) |
Close a connection
Implements Varien_Io_Interface.
Definition at line 155 of file Ftp.php.
ls | ( | $ | grep = null |
) |
Get list of cwd subdirectories and files
Implements Varien_Io_Interface.
Definition at line 305 of file Ftp.php.
00306 { 00307 $ls = @ftp_nlist($this->_conn, '.'); 00308 00309 $list = array(); 00310 foreach ($ls as $file) { 00311 $list[] = array( 00312 'text'=>$file, 00313 'id'=>$this->pwd().'/'.$file, 00314 ); 00315 } 00316 00317 return $list; 00318 }
mkdir | ( | $ | dir, | |
$ | mode = 0777 , |
|||
$ | recursive = true | |||
) |
Create a directory
string | $dir | |
int | $mode | |
boolean | $recursive |
Implements Varien_Io_Interface.
Definition at line 169 of file Ftp.php.
mv | ( | $ | src, | |
$ | dest | |||
) |
Rename or move a directory or a file
string | $src | |
string | $dest |
Implements Varien_Io_Interface.
Definition at line 288 of file Ftp.php.
Open a connection
Possible argument keys:
array | $args |
Reimplemented from Varien_Io_Abstract.
Definition at line 85 of file Ftp.php.
00086 { 00087 if (empty($args['host'])) { 00088 $this->_error = self::ERROR_EMPTY_HOST; 00089 throw new Varien_Io_Exception('Empty host specified'); 00090 } 00091 00092 if (empty($args['port'])) { 00093 $args['port'] = 21; 00094 } 00095 00096 if (empty($args['user'])) { 00097 $args['user'] = 'anonymous'; 00098 $args['password'] = 'anonymous@noserver.com'; 00099 } 00100 00101 if (empty($args['password'])) { 00102 $args['password'] = ''; 00103 } 00104 00105 if (empty($args['timeout'])) { 00106 $args['timeout'] = 90; 00107 } 00108 00109 if (empty($args['file_mode'])) { 00110 $args['file_mode'] = FTP_BINARY; 00111 } 00112 00113 $this->_config = $args; 00114 00115 if (empty($this->_config['ssl'])) { 00116 $this->_conn = @ftp_connect($this->_config['host'], $this->_config['port'], $this->_config['timeout']); 00117 } else { 00118 $this->_conn = @ftp_ssl_connect($this->_config['host'], $this->_config['port'], $this->_config['timeout']); 00119 } 00120 if (!$this->_conn) { 00121 $this->_error = self::ERROR_INVALID_CONNECTION; 00122 throw new Varien_Io_Exception('Could not establish FTP connection, invalid host or port'); 00123 } 00124 00125 if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password'])) { 00126 $this->_error = self::ERROR_INVALID_LOGIN; 00127 $this->close(); 00128 throw new Varien_Io_Exception('Invalid user name or password'); 00129 } 00130 00131 if (!empty($this->_config['path'])) { 00132 if (!@ftp_chdir($this->_conn, $this->_config['path'])) { 00133 $this->_error = self::ERROR_INVALID_PATH; 00134 $this->close(); 00135 throw new Varien_Io_Exception('Invalid path'); 00136 } 00137 } 00138 00139 if (!empty($this->_config['passive'])) { 00140 if (!@ftp_pasv($this->_conn, true)) { 00141 $this->_error = self::ERROR_INVALID_MODE; 00142 $this->close(); 00143 throw new Varien_Io_Exception('Invalid file transfer mode'); 00144 } 00145 } 00146 00147 return true; 00148 }
pwd | ( | ) |
Get current working directory
Implements Varien_Io_Interface.
Definition at line 190 of file Ftp.php.
read | ( | $ | filename, | |
$ | dest = null | |||
) |
Read a file to result, file or stream
string | $filename | |
string|resource|null | $dest destination file name, stream, or if null will return file contents |
Implements Varien_Io_Interface.
Definition at line 213 of file Ftp.php.
00214 { 00215 if (is_string($dest)) { 00216 $result = ftp_get($this->_conn, $dest, $filename, $this->_config['file_mode']); 00217 } else { 00218 if (is_resource($dest)) { 00219 $stream = $dest; 00220 } elseif (is_null($dest)) { 00221 $stream = tmpfile(); 00222 } else { 00223 $this->_error = self::ERROR_INVALID_DESTINATION; 00224 return false; 00225 } 00226 00227 $result = ftp_fget($this->_conn, $stream, $filename, $this->_config['file_mode']); 00228 00229 if (is_null($dest)) { 00230 fseek($stream, 0); 00231 $result = ''; 00232 for ($result = ''; $s = fread($stream, 4096); $result .= $s); 00233 fclose($stream); 00234 } 00235 } 00236 return $result; 00237 }
rm | ( | $ | filename | ) |
Delete a file
string | $filename |
Implements Varien_Io_Interface.
Definition at line 276 of file Ftp.php.
rmdir | ( | $ | dir, | |
$ | recursive = false | |||
) |
Delete a directory
string | $dir |
Implements Varien_Io_Interface.
Definition at line 180 of file Ftp.php.
write | ( | $ | filename, | |
$ | src, | |||
$ | mode = null | |||
) |
Write a file from string, file or stream
string | $filename | |
string|resource | $src filename, string data or source stream |
Implements Varien_Io_Interface.
Definition at line 246 of file Ftp.php.
00247 { 00248 if (is_string($src) && is_readable($src)) { 00249 return @ftp_put($this->_conn, $filename, $src, $this->_config['file_mode']); 00250 } else { 00251 if (is_string($src)) { 00252 $stream = tmpfile(); 00253 fputs($stream, $src); 00254 fseek($stream, 0); 00255 } elseif (is_resource($src)) { 00256 $stream = $src; 00257 } else { 00258 $this->_error = self::ERROR_INVALID_SOURCE; 00259 return false; 00260 } 00261 00262 $result = ftp_fput($this->_conn, $filename, $stream, $this->_config['file_mode']); 00263 if (is_string($src)) { 00264 fclose($stream); 00265 } 00266 return $result; 00267 } 00268 }
const ERROR_EMPTY_HOST = 1 |
const ERROR_INVALID_CONNECTION = 2 |
const ERROR_INVALID_DESTINATION = 6 |
const ERROR_INVALID_LOGIN = 3 |
const ERROR_INVALID_MODE = 5 |
const ERROR_INVALID_PATH = 4 |
const ERROR_INVALID_SOURCE = 7 |