author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 11:56:20 +0200 | |
changeset 12 | d8a8807227e4 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Filesystem Class for implementing SSH2 |
|
4 |
* |
|
5 |
* To use this class you must follow these steps for PHP 5.2.6+ |
|
6 |
* |
|
7 |
* @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes |
|
8 |
* |
|
9 |
* Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work) |
|
10 |
* |
|
11 |
* cd /usr/src |
|
12 |
* wget http://surfnet.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.14.tar.gz |
|
13 |
* tar -zxvf libssh2-0.14.tar.gz |
|
14 |
* cd libssh2-0.14/ |
|
15 |
* ./configure |
|
16 |
* make all install |
|
17 |
* |
|
18 |
* Note: Do not leave the directory yet! |
|
19 |
* |
|
20 |
* Enter: pecl install -f ssh2 |
|
21 |
* |
|
22 |
* Copy the ssh.so file it creates to your PHP Module Directory. |
|
23 |
* Open up your PHP.INI file and look for where extensions are placed. |
|
24 |
* Add in your PHP.ini file: extension=ssh2.so |
|
25 |
* |
|
26 |
* Restart Apache! |
|
27 |
* Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist. |
|
28 |
* |
|
29 |
* Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents' |
|
30 |
* |
|
31 |
* @since 2.7.0 |
|
32 |
* |
|
33 |
* @package WordPress |
|
34 |
* @subpackage Filesystem |
|
35 |
*/ |
|
36 |
class WP_Filesystem_SSH2 extends WP_Filesystem_Base { |
|
37 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
/** |
9 | 39 |
* @since 2.7.0 |
40 |
* @var resource |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
*/ |
5 | 42 |
public $link = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
|
5 | 44 |
/** |
9 | 45 |
* @since 2.7.0 |
5 | 46 |
* @var resource |
47 |
*/ |
|
48 |
public $sftp_link; |
|
9 | 49 |
|
50 |
/** |
|
51 |
* @since 2.7.0 |
|
52 |
* @var bool |
|
53 |
*/ |
|
5 | 54 |
public $keys = false; |
0 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
/** |
9 | 57 |
* Constructor. |
58 |
* |
|
59 |
* @since 2.7.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @param array $opt |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
public function __construct( $opt = '' ) { |
0 | 64 |
$this->method = 'ssh2'; |
65 |
$this->errors = new WP_Error(); |
|
66 |
||
67 |
//Check if possible to use ssh2 functions. |
|
9 | 68 |
if ( ! extension_loaded( 'ssh2' ) ) { |
69 |
$this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) ); |
|
5 | 70 |
return; |
0 | 71 |
} |
9 | 72 |
if ( ! function_exists( 'stream_get_contents' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
$this->errors->add( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
'ssh2_php_requirement', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
/* translators: %s: stream_get_contents() */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
__( 'The ssh2 PHP extension is available, however, we require the PHP5 function %s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
'<code>stream_get_contents()</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
); |
5 | 81 |
return; |
0 | 82 |
} |
83 |
||
84 |
// Set defaults: |
|
9 | 85 |
if ( empty( $opt['port'] ) ) { |
0 | 86 |
$this->options['port'] = 22; |
9 | 87 |
} else { |
0 | 88 |
$this->options['port'] = $opt['port']; |
9 | 89 |
} |
0 | 90 |
|
9 | 91 |
if ( empty( $opt['hostname'] ) ) { |
92 |
$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) ); |
|
93 |
} else { |
|
0 | 94 |
$this->options['hostname'] = $opt['hostname']; |
9 | 95 |
} |
0 | 96 |
|
97 |
// Check if the options provided are OK. |
|
9 | 98 |
if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) { |
99 |
$this->options['public_key'] = $opt['public_key']; |
|
0 | 100 |
$this->options['private_key'] = $opt['private_key']; |
101 |
||
9 | 102 |
$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa' ); |
0 | 103 |
|
104 |
$this->keys = true; |
|
9 | 105 |
} elseif ( empty( $opt['username'] ) ) { |
106 |
$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) ); |
|
0 | 107 |
} |
108 |
||
9 | 109 |
if ( ! empty( $opt['username'] ) ) { |
0 | 110 |
$this->options['username'] = $opt['username']; |
9 | 111 |
} |
0 | 112 |
|
9 | 113 |
if ( empty( $opt['password'] ) ) { |
5 | 114 |
// Password can be blank if we are using keys. |
9 | 115 |
if ( ! $this->keys ) { |
116 |
$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) ); |
|
117 |
} |
|
0 | 118 |
} else { |
119 |
$this->options['password'] = $opt['password']; |
|
120 |
} |
|
121 |
} |
|
122 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
/** |
9 | 124 |
* Connects filesystem. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* |
9 | 126 |
* @since 2.7.0 |
127 |
* |
|
128 |
* @return bool True on success, false on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
*/ |
5 | 130 |
public function connect() { |
0 | 131 |
if ( ! $this->keys ) { |
9 | 132 |
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] ); |
0 | 133 |
} else { |
9 | 134 |
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] ); |
0 | 135 |
} |
136 |
||
137 |
if ( ! $this->link ) { |
|
9 | 138 |
$this->errors->add( |
139 |
'connect', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
/* translators: %s: hostname:port */ |
9 | 141 |
sprintf( |
142 |
__( 'Failed to connect to SSH2 Server %s' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
); |
0 | 146 |
return false; |
147 |
} |
|
148 |
||
9 | 149 |
if ( ! $this->keys ) { |
150 |
if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) { |
|
151 |
$this->errors->add( |
|
152 |
'auth', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
/* translators: %s: username */ |
9 | 154 |
sprintf( |
155 |
__( 'Username/Password incorrect for %s' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
$this->options['username'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
); |
0 | 159 |
return false; |
160 |
} |
|
161 |
} else { |
|
9 | 162 |
if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { |
163 |
$this->errors->add( |
|
164 |
'auth', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
/* translators: %s: username */ |
9 | 166 |
sprintf( |
167 |
__( 'Public and Private keys incorrect for %s' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
$this->options['username'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
); |
0 | 171 |
return false; |
172 |
} |
|
173 |
} |
|
174 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
$this->sftp_link = ssh2_sftp( $this->link ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
if ( ! $this->sftp_link ) { |
9 | 177 |
$this->errors->add( |
178 |
'connect', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
/* translators: %s: hostname:port */ |
9 | 180 |
sprintf( |
181 |
__( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
} |
0 | 187 |
|
188 |
return true; |
|
189 |
} |
|
190 |
||
5 | 191 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* Gets the ssh2.sftp PHP stream wrapper path to open for the given file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* This method also works around a PHP bug where the root directory (/) cannot |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* be opened by PHP functions, causing a false failure. In order to work around |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* this, the path is converted to /./ which is semantically the same as / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* See https://bugs.php.net/bug.php?id=64169 for more details. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
* @param string $path The File/Directory path on the remote server to return |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* @return string The ssh2.sftp:// wrapped path to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
public function sftp_path( $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
if ( '/' === $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
$path = '/./'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
/** |
9 | 212 |
* @since 2.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* |
5 | 214 |
* @param string $command |
215 |
* @param bool $returnbool |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
* @return bool|string True on success, false on failure. String if the command was executed, `$returnbool` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
* is false (default), and data from the resulting stream was retrieved. |
5 | 218 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
public function run_command( $command, $returnbool = false ) { |
9 | 220 |
if ( ! $this->link ) { |
0 | 221 |
return false; |
9 | 222 |
} |
0 | 223 |
|
9 | 224 |
if ( ! ( $stream = ssh2_exec( $this->link, $command ) ) ) { |
225 |
$this->errors->add( |
|
226 |
'command', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
/* translators: %s: command */ |
9 | 228 |
sprintf( |
229 |
__( 'Unable to perform command: %s' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
$command |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
); |
0 | 233 |
} else { |
234 |
stream_set_blocking( $stream, true ); |
|
235 |
stream_set_timeout( $stream, FS_TIMEOUT ); |
|
236 |
$data = stream_get_contents( $stream ); |
|
237 |
fclose( $stream ); |
|
238 |
||
9 | 239 |
if ( $returnbool ) { |
240 |
return ( $data === false ) ? false : '' != trim( $data ); |
|
241 |
} else { |
|
0 | 242 |
return $data; |
9 | 243 |
} |
0 | 244 |
} |
245 |
return false; |
|
246 |
} |
|
247 |
||
5 | 248 |
/** |
9 | 249 |
* Reads entire file into a string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* |
9 | 251 |
* @since 2.7.0 |
252 |
* |
|
253 |
* @param string $file Name of the file to read. |
|
254 |
* @return string|false Read data on success, false if no temporary file could be opened, |
|
255 |
* or if the file couldn't be retrieved. |
|
5 | 256 |
*/ |
257 |
public function get_contents( $file ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
return file_get_contents( $this->sftp_path( $file ) ); |
0 | 259 |
} |
260 |
||
5 | 261 |
/** |
9 | 262 |
* Reads entire file into an array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
* |
9 | 264 |
* @since 2.7.0 |
265 |
* |
|
266 |
* @param string $file Path to the file. |
|
267 |
* @return array|false File contents in an array on success, false on failure. |
|
5 | 268 |
*/ |
9 | 269 |
public function get_contents_array( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
return file( $this->sftp_path( $file ) ); |
0 | 271 |
} |
272 |
||
5 | 273 |
/** |
9 | 274 |
* Writes a string to a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* |
9 | 276 |
* @since 2.7.0 |
277 |
* |
|
278 |
* @param string $file Remote path to the file where to write the data. |
|
279 |
* @param string $contents The data to write. |
|
280 |
* @param int|false $mode Optional. The file permissions as octal number, usually 0644. |
|
281 |
* Default false. |
|
282 |
* @return bool True on success, false on failure. |
|
5 | 283 |
*/ |
9 | 284 |
public function put_contents( $file, $contents, $mode = false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
$ret = file_put_contents( $this->sftp_path( $file ), $contents ); |
0 | 286 |
|
9 | 287 |
if ( $ret !== strlen( $contents ) ) { |
0 | 288 |
return false; |
9 | 289 |
} |
0 | 290 |
|
9 | 291 |
$this->chmod( $file, $mode ); |
0 | 292 |
|
293 |
return true; |
|
294 |
} |
|
295 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
/** |
9 | 297 |
* Gets the current working directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* |
9 | 299 |
* @since 2.7.0 |
300 |
* |
|
301 |
* @return string|false The current working directory on success, false on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
*/ |
5 | 303 |
public function cwd() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
$cwd = ssh2_sftp_realpath( $this->sftp_link, '.' ); |
5 | 305 |
if ( $cwd ) { |
306 |
$cwd = trailingslashit( trim( $cwd ) ); |
|
307 |
} |
|
0 | 308 |
return $cwd; |
309 |
} |
|
310 |
||
5 | 311 |
/** |
9 | 312 |
* Changes current directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* |
9 | 314 |
* @since 2.7.0 |
315 |
* |
|
316 |
* @param string $dir The new current directory. |
|
317 |
* @return bool True on success, false on failure. |
|
5 | 318 |
*/ |
9 | 319 |
public function chdir( $dir ) { |
320 |
return $this->run_command( 'cd ' . $dir, true ); |
|
0 | 321 |
} |
322 |
||
5 | 323 |
/** |
9 | 324 |
* Changes the file group. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
9 | 326 |
* @since 2.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* |
9 | 328 |
* @param string $file Path to the file. |
329 |
* @param string|int $group A group name or number. |
|
330 |
* @param bool $recursive Optional. If set to true, changes file group recursively. |
|
331 |
* Default false. |
|
332 |
* @return bool True on success, false on failure. |
|
5 | 333 |
*/ |
9 | 334 |
public function chgrp( $file, $group, $recursive = false ) { |
335 |
if ( ! $this->exists( $file ) ) { |
|
0 | 336 |
return false; |
9 | 337 |
} |
338 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
|
339 |
return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); |
|
340 |
} |
|
341 |
return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); |
|
0 | 342 |
} |
343 |
||
5 | 344 |
/** |
9 | 345 |
* Changes filesystem permissions. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
* |
9 | 347 |
* @since 2.7.0 |
348 |
* |
|
349 |
* @param string $file Path to the file. |
|
350 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
351 |
* 0755 for directories. Default false. |
|
352 |
* @param bool $recursive Optional. If set to true, changes file group recursively. |
|
353 |
* Default false. |
|
354 |
* @return bool True on success, false on failure. |
|
5 | 355 |
*/ |
9 | 356 |
public function chmod( $file, $mode = false, $recursive = false ) { |
357 |
if ( ! $this->exists( $file ) ) { |
|
0 | 358 |
return false; |
9 | 359 |
} |
0 | 360 |
|
361 |
if ( ! $mode ) { |
|
9 | 362 |
if ( $this->is_file( $file ) ) { |
0 | 363 |
$mode = FS_CHMOD_FILE; |
9 | 364 |
} elseif ( $this->is_dir( $file ) ) { |
0 | 365 |
$mode = FS_CHMOD_DIR; |
9 | 366 |
} else { |
0 | 367 |
return false; |
9 | 368 |
} |
0 | 369 |
} |
370 |
||
9 | 371 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
372 |
return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true ); |
|
373 |
} |
|
374 |
return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true ); |
|
0 | 375 |
} |
376 |
||
377 |
/** |
|
9 | 378 |
* Changes the owner of a file or directory. |
0 | 379 |
* |
9 | 380 |
* @since 2.7.0 |
0 | 381 |
* |
9 | 382 |
* @param string $file Path to the file or directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* @param string|int $owner A user name or number. |
9 | 384 |
* @param bool $recursive Optional. If set to true, changes file owner recursively. |
385 |
* Default false. |
|
386 |
* @return bool True on success, false on failure. |
|
0 | 387 |
*/ |
5 | 388 |
public function chown( $file, $owner, $recursive = false ) { |
9 | 389 |
if ( ! $this->exists( $file ) ) { |
0 | 390 |
return false; |
9 | 391 |
} |
392 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
|
393 |
return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); |
|
394 |
} |
|
395 |
return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); |
|
0 | 396 |
} |
397 |
||
5 | 398 |
/** |
9 | 399 |
* Gets the file owner. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
* |
9 | 401 |
* @since 2.7.0 |
402 |
* |
|
403 |
* @param string $file Path to the file. |
|
404 |
* @return string|false Username of the owner on success, false on failure. |
|
5 | 405 |
*/ |
9 | 406 |
public function owner( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
$owneruid = @fileowner( $this->sftp_path( $file ) ); |
9 | 408 |
if ( ! $owneruid ) { |
0 | 409 |
return false; |
9 | 410 |
} |
411 |
if ( ! function_exists( 'posix_getpwuid' ) ) { |
|
0 | 412 |
return $owneruid; |
9 | 413 |
} |
414 |
$ownerarray = posix_getpwuid( $owneruid ); |
|
0 | 415 |
return $ownerarray['name']; |
416 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
|
5 | 418 |
/** |
9 | 419 |
* Gets the permissions of the specified file or filepath in their octal format. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
* |
9 | 421 |
* @since 2.7.0 |
422 |
* |
|
423 |
* @param string $file Path to the file. |
|
424 |
* @return string Mode of the file (the last 3 digits). |
|
5 | 425 |
*/ |
9 | 426 |
public function getchmod( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 ); |
0 | 428 |
} |
429 |
||
5 | 430 |
/** |
9 | 431 |
* Gets the file's group. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* |
9 | 433 |
* @since 2.7.0 |
434 |
* |
|
435 |
* @param string $file Path to the file. |
|
436 |
* @return string|false The group on success, false on failure. |
|
5 | 437 |
*/ |
9 | 438 |
public function group( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$gid = @filegroup( $this->sftp_path( $file ) ); |
9 | 440 |
if ( ! $gid ) { |
0 | 441 |
return false; |
9 | 442 |
} |
443 |
if ( ! function_exists( 'posix_getgrgid' ) ) { |
|
0 | 444 |
return $gid; |
9 | 445 |
} |
446 |
$grouparray = posix_getgrgid( $gid ); |
|
0 | 447 |
return $grouparray['name']; |
448 |
} |
|
449 |
||
5 | 450 |
/** |
9 | 451 |
* Copies a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* |
9 | 453 |
* @since 2.7.0 |
454 |
* |
|
455 |
* @param string $source Path to the source file. |
|
456 |
* @param string $destination Path to the destination file. |
|
457 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
458 |
* Default false. |
|
459 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
460 |
* 0755 for dirs. Default false. |
|
461 |
* @return bool True on success, false on failure. |
|
5 | 462 |
*/ |
9 | 463 |
public function copy( $source, $destination, $overwrite = false, $mode = false ) { |
464 |
if ( ! $overwrite && $this->exists( $destination ) ) { |
|
0 | 465 |
return false; |
9 | 466 |
} |
467 |
$content = $this->get_contents( $source ); |
|
468 |
if ( false === $content ) { |
|
0 | 469 |
return false; |
9 | 470 |
} |
471 |
return $this->put_contents( $destination, $content, $mode ); |
|
0 | 472 |
} |
473 |
||
5 | 474 |
/** |
9 | 475 |
* Moves a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* |
9 | 477 |
* @since 2.7.0 |
478 |
* |
|
479 |
* @param string $source Path to the source file. |
|
480 |
* @param string $destination Path to the destination file. |
|
481 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
482 |
* Default false. |
|
483 |
* @return bool True on success, false on failure. |
|
5 | 484 |
*/ |
9 | 485 |
public function move( $source, $destination, $overwrite = false ) { |
5 | 486 |
return @ssh2_sftp_rename( $this->sftp_link, $source, $destination ); |
0 | 487 |
} |
488 |
||
5 | 489 |
/** |
9 | 490 |
* Deletes a file or directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* |
9 | 492 |
* @since 2.7.0 |
493 |
* |
|
494 |
* @param string $file Path to the file or directory. |
|
495 |
* @param bool $recursive Optional. If set to true, changes file group recursively. |
|
496 |
* Default false. |
|
497 |
* @param string|false $type Type of resource. 'f' for file, 'd' for directory. |
|
498 |
* Default false. |
|
499 |
* @return bool True on success, false on failure. |
|
5 | 500 |
*/ |
9 | 501 |
public function delete( $file, $recursive = false, $type = false ) { |
502 |
if ( 'f' == $type || $this->is_file( $file ) ) { |
|
503 |
return ssh2_sftp_unlink( $this->sftp_link, $file ); |
|
504 |
} |
|
505 |
if ( ! $recursive ) { |
|
506 |
return ssh2_sftp_rmdir( $this->sftp_link, $file ); |
|
507 |
} |
|
508 |
$filelist = $this->dirlist( $file ); |
|
509 |
if ( is_array( $filelist ) ) { |
|
510 |
foreach ( $filelist as $filename => $fileinfo ) { |
|
511 |
$this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] ); |
|
0 | 512 |
} |
513 |
} |
|
9 | 514 |
return ssh2_sftp_rmdir( $this->sftp_link, $file ); |
0 | 515 |
} |
516 |
||
5 | 517 |
/** |
9 | 518 |
* Checks if a file or directory exists. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* |
9 | 520 |
* @since 2.7.0 |
521 |
* |
|
522 |
* @param string $file Path to file or directory. |
|
523 |
* @return bool Whether $file exists or not. |
|
5 | 524 |
*/ |
9 | 525 |
public function exists( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
return file_exists( $this->sftp_path( $file ) ); |
0 | 527 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
|
5 | 529 |
/** |
9 | 530 |
* Checks if resource is a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* |
9 | 532 |
* @since 2.7.0 |
533 |
* |
|
534 |
* @param string $file File path. |
|
535 |
* @return bool Whether $file is a file. |
|
5 | 536 |
*/ |
9 | 537 |
public function is_file( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
return is_file( $this->sftp_path( $file ) ); |
0 | 539 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
|
5 | 541 |
/** |
9 | 542 |
* Checks if resource is a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
* |
9 | 544 |
* @since 2.7.0 |
545 |
* |
|
546 |
* @param string $path Directory path. |
|
547 |
* @return bool Whether $path is a directory. |
|
5 | 548 |
*/ |
9 | 549 |
public function is_dir( $path ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
return is_dir( $this->sftp_path( $path ) ); |
0 | 551 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
|
5 | 553 |
/** |
9 | 554 |
* Checks if a file is readable. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
* |
9 | 556 |
* @since 2.7.0 |
557 |
* |
|
558 |
* @param string $file Path to file. |
|
559 |
* @return bool Whether $file is readable. |
|
5 | 560 |
*/ |
9 | 561 |
public function is_readable( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
return is_readable( $this->sftp_path( $file ) ); |
0 | 563 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
|
5 | 565 |
/** |
9 | 566 |
* Checks if a file or directory is writable. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* |
9 | 568 |
* @since 2.7.0 |
569 |
* |
|
570 |
* @param string $file Path to file or directory. |
|
571 |
* @return bool Whether $file is writable. |
|
5 | 572 |
*/ |
9 | 573 |
public function is_writable( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
// PHP will base it's writable checks on system_user === file_owner, not ssh_user === file_owner |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
return true; |
0 | 576 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
|
5 | 578 |
/** |
9 | 579 |
* Gets the file's last access time. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* |
9 | 581 |
* @since 2.7.0 |
582 |
* |
|
583 |
* @param string $file Path to file. |
|
584 |
* @return int|false Unix timestamp representing last access time, false on failure. |
|
5 | 585 |
*/ |
9 | 586 |
public function atime( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
return fileatime( $this->sftp_path( $file ) ); |
0 | 588 |
} |
589 |
||
5 | 590 |
/** |
9 | 591 |
* Gets the file modification time. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* |
9 | 593 |
* @since 2.7.0 |
594 |
* |
|
595 |
* @param string $file Path to file. |
|
596 |
* @return int|false Unix timestamp representing modification time, false on failure. |
|
5 | 597 |
*/ |
9 | 598 |
public function mtime( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
return filemtime( $this->sftp_path( $file ) ); |
0 | 600 |
} |
601 |
||
5 | 602 |
/** |
9 | 603 |
* Gets the file size (in bytes). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* |
9 | 605 |
* @since 2.7.0 |
606 |
* |
|
607 |
* @param string $file Path to file. |
|
608 |
* @return int|false Size of the file in bytes on success, false on failure. |
|
5 | 609 |
*/ |
9 | 610 |
public function size( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
return filesize( $this->sftp_path( $file ) ); |
0 | 612 |
} |
613 |
||
5 | 614 |
/** |
9 | 615 |
* Sets the access and modification times of a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* |
9 | 617 |
* Note: Not implemented. |
618 |
* |
|
619 |
* @since 2.7.0 |
|
620 |
* |
|
621 |
* @param string $file Path to file. |
|
622 |
* @param int $time Optional. Modified time to set for file. |
|
623 |
* Default 0. |
|
624 |
* @param int $atime Optional. Access time to set for file. |
|
625 |
* Default 0. |
|
5 | 626 |
*/ |
9 | 627 |
public function touch( $file, $time = 0, $atime = 0 ) { |
628 |
// Not implemented. |
|
0 | 629 |
} |
630 |
||
5 | 631 |
/** |
9 | 632 |
* Creates a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* |
9 | 634 |
* @since 2.7.0 |
635 |
* |
|
636 |
* @param string $path Path for new directory. |
|
637 |
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod). |
|
638 |
* Default false. |
|
639 |
* @param string|int $chown Optional. A user name or number (or false to skip chown). |
|
640 |
* Default false. |
|
641 |
* @param string|int $chgrp Optional. A group name or number (or false to skip chgrp). |
|
642 |
* Default false. |
|
643 |
* @return bool True on success, false on failure. |
|
5 | 644 |
*/ |
9 | 645 |
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { |
646 |
$path = untrailingslashit( $path ); |
|
647 |
if ( empty( $path ) ) { |
|
0 | 648 |
return false; |
9 | 649 |
} |
0 | 650 |
|
9 | 651 |
if ( ! $chmod ) { |
0 | 652 |
$chmod = FS_CHMOD_DIR; |
9 | 653 |
} |
654 |
if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) { |
|
0 | 655 |
return false; |
9 | 656 |
} |
657 |
if ( $chown ) { |
|
658 |
$this->chown( $path, $chown ); |
|
659 |
} |
|
660 |
if ( $chgrp ) { |
|
661 |
$this->chgrp( $path, $chgrp ); |
|
662 |
} |
|
0 | 663 |
return true; |
664 |
} |
|
665 |
||
5 | 666 |
/** |
9 | 667 |
* Deletes a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
* |
9 | 669 |
* @since 2.7.0 |
670 |
* |
|
671 |
* @param string $path Path to directory. |
|
672 |
* @param bool $recursive Optional. Whether to recursively remove files/directories. |
|
673 |
* Default false. |
|
674 |
* @return bool True on success, false on failure. |
|
5 | 675 |
*/ |
9 | 676 |
public function rmdir( $path, $recursive = false ) { |
677 |
return $this->delete( $path, $recursive ); |
|
0 | 678 |
} |
679 |
||
5 | 680 |
/** |
9 | 681 |
* Gets details for files in a directory or a specific file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
* |
9 | 683 |
* @since 2.7.0 |
684 |
* |
|
685 |
* @param string $path Path to directory or file. |
|
686 |
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. |
|
687 |
* Default true. |
|
688 |
* @param bool $recursive Optional. Whether to recursively include file details in nested directories. |
|
689 |
* Default false. |
|
690 |
* @return array|false { |
|
691 |
* Array of files. False if unable to list directory contents. |
|
692 |
* |
|
693 |
* @type string $name Name of the file or directory. |
|
694 |
* @type string $perms *nix representation of permissions. |
|
695 |
* @type int $permsn Octal representation of permissions. |
|
696 |
* @type string $owner Owner name or ID. |
|
697 |
* @type int $size Size of file in bytes. |
|
698 |
* @type int $lastmodunix Last modified unix timestamp. |
|
699 |
* @type mixed $lastmod Last modified month (3 letter) and day (without leading 0). |
|
700 |
* @type int $time Last modified time. |
|
701 |
* @type string $type Type of resource. 'f' for file, 'd' for directory. |
|
702 |
* @type mixed $files If a directory and $recursive is true, contains another array of files. |
|
703 |
* } |
|
5 | 704 |
*/ |
9 | 705 |
public function dirlist( $path, $include_hidden = true, $recursive = false ) { |
706 |
if ( $this->is_file( $path ) ) { |
|
707 |
$limit_file = basename( $path ); |
|
708 |
$path = dirname( $path ); |
|
0 | 709 |
} else { |
710 |
$limit_file = false; |
|
711 |
} |
|
712 |
||
9 | 713 |
if ( ! $this->is_dir( $path ) ) { |
0 | 714 |
return false; |
9 | 715 |
} |
0 | 716 |
|
717 |
$ret = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
$dir = @dir( $this->sftp_path( $path ) ); |
0 | 719 |
|
9 | 720 |
if ( ! $dir ) { |
0 | 721 |
return false; |
9 | 722 |
} |
0 | 723 |
|
9 | 724 |
while ( false !== ( $entry = $dir->read() ) ) { |
725 |
$struc = array(); |
|
0 | 726 |
$struc['name'] = $entry; |
727 |
||
9 | 728 |
if ( '.' == $struc['name'] || '..' == $struc['name'] ) { |
0 | 729 |
continue; //Do not care about these folders. |
9 | 730 |
} |
0 | 731 |
|
9 | 732 |
if ( ! $include_hidden && '.' == $struc['name'][0] ) { |
0 | 733 |
continue; |
9 | 734 |
} |
0 | 735 |
|
9 | 736 |
if ( $limit_file && $struc['name'] != $limit_file ) { |
737 |
continue; |
|
738 |
} |
|
739 |
||
740 |
$struc['perms'] = $this->gethchmod( $path . '/' . $entry ); |
|
741 |
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); |
|
742 |
$struc['number'] = false; |
|
743 |
$struc['owner'] = $this->owner( $path . '/' . $entry ); |
|
744 |
$struc['group'] = $this->group( $path . '/' . $entry ); |
|
745 |
$struc['size'] = $this->size( $path . '/' . $entry ); |
|
746 |
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry ); |
|
747 |
$struc['lastmod'] = date( 'M j', $struc['lastmodunix'] ); |
|
748 |
$struc['time'] = date( 'h:i:s', $struc['lastmodunix'] ); |
|
749 |
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; |
|
0 | 750 |
|
751 |
if ( 'd' == $struc['type'] ) { |
|
9 | 752 |
if ( $recursive ) { |
753 |
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); |
|
754 |
} else { |
|
0 | 755 |
$struc['files'] = array(); |
9 | 756 |
} |
0 | 757 |
} |
758 |
||
759 |
$ret[ $struc['name'] ] = $struc; |
|
760 |
} |
|
761 |
$dir->close(); |
|
9 | 762 |
unset( $dir ); |
0 | 763 |
return $ret; |
764 |
} |
|
765 |
} |