author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress FTP Sockets Filesystem. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Filesystem |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* WordPress Filesystem Class for implementing FTP Sockets. |
|
11 |
* |
|
5 | 12 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @see WP_Filesystem_Base |
0 | 15 |
*/ |
16 |
class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { |
|
5 | 17 |
/** |
18 |
* @var ftp |
|
19 |
*/ |
|
20 |
public $ftp; |
|
0 | 21 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @param array $opt |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
public function __construct( $opt = '' ) { |
0 | 27 |
$this->method = 'ftpsockets'; |
28 |
$this->errors = new WP_Error(); |
|
29 |
||
30 |
// Check if possible to use ftp functions. |
|
5 | 31 |
if ( ! @include_once( ABSPATH . 'wp-admin/includes/class-ftp.php' ) ) { |
32 |
return; |
|
33 |
} |
|
0 | 34 |
$this->ftp = new ftp(); |
35 |
||
36 |
if ( empty($opt['port']) ) |
|
37 |
$this->options['port'] = 21; |
|
38 |
else |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
$this->options['port'] = (int) $opt['port']; |
0 | 40 |
|
41 |
if ( empty($opt['hostname']) ) |
|
42 |
$this->errors->add('empty_hostname', __('FTP hostname is required')); |
|
43 |
else |
|
44 |
$this->options['hostname'] = $opt['hostname']; |
|
45 |
||
46 |
// Check if the options provided are OK. |
|
47 |
if ( empty ($opt['username']) ) |
|
48 |
$this->errors->add('empty_username', __('FTP username is required')); |
|
49 |
else |
|
50 |
$this->options['username'] = $opt['username']; |
|
51 |
||
52 |
if ( empty ($opt['password']) ) |
|
53 |
$this->errors->add('empty_password', __('FTP password is required')); |
|
54 |
else |
|
55 |
$this->options['password'] = $opt['password']; |
|
56 |
} |
|
57 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
*/ |
5 | 62 |
public function connect() { |
0 | 63 |
if ( ! $this->ftp ) |
64 |
return false; |
|
65 |
||
66 |
$this->ftp->setTimeout(FS_CONNECT_TIMEOUT); |
|
67 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
$this->errors->add( 'connect', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
/* translators: %s: hostname:port */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
sprintf( __( 'Failed to connect to FTP Server %s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
); |
0 | 75 |
return false; |
76 |
} |
|
77 |
||
78 |
if ( ! $this->ftp->connect() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
$this->errors->add( 'connect', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
/* translators: %s: hostname:port */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
sprintf( __( 'Failed to connect to FTP Server %s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
); |
0 | 85 |
return false; |
86 |
} |
|
87 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
if ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
$this->errors->add( 'auth', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
/* translators: %s: username */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
sprintf( __( 'Username/Password incorrect for %s' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
$this->options['username'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
); |
0 | 95 |
return false; |
96 |
} |
|
97 |
||
98 |
$this->ftp->SetType( FTP_BINARY ); |
|
99 |
$this->ftp->Passive( true ); |
|
100 |
$this->ftp->setTimeout( FS_TIMEOUT ); |
|
101 |
return true; |
|
102 |
} |
|
103 |
||
5 | 104 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* Retrieves the file contents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* @param string $file Filename. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* @return string|false File contents on success, false if no temp file could be opened, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* or if the file doesn't exist. |
5 | 112 |
*/ |
113 |
public function get_contents( $file ) { |
|
0 | 114 |
if ( ! $this->exists($file) ) |
115 |
return false; |
|
116 |
||
117 |
$temp = wp_tempnam( $file ); |
|
118 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
if ( ! $temphandle = fopen( $temp, 'w+' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
unlink( $temp ); |
0 | 121 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
} |
0 | 123 |
|
124 |
mbstring_binary_safe_encoding(); |
|
125 |
||
126 |
if ( ! $this->ftp->fget($temphandle, $file) ) { |
|
127 |
fclose($temphandle); |
|
128 |
unlink($temp); |
|
129 |
||
130 |
reset_mbstring_encoding(); |
|
131 |
||
132 |
return ''; // Blank document, File does exist, It's just blank. |
|
133 |
} |
|
134 |
||
135 |
reset_mbstring_encoding(); |
|
136 |
||
137 |
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to |
|
138 |
$contents = ''; |
|
139 |
||
140 |
while ( ! feof($temphandle) ) |
|
141 |
$contents .= fread($temphandle, 8192); |
|
142 |
||
143 |
fclose($temphandle); |
|
144 |
unlink($temp); |
|
145 |
return $contents; |
|
146 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
|
5 | 148 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
* |
5 | 150 |
* @param string $file |
151 |
* @return array |
|
152 |
*/ |
|
153 |
public function get_contents_array($file) { |
|
0 | 154 |
return explode("\n", $this->get_contents($file) ); |
155 |
} |
|
156 |
||
5 | 157 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* |
5 | 159 |
* @param string $file |
160 |
* @param string $contents |
|
161 |
* @param int|bool $mode |
|
162 |
* @return bool |
|
163 |
*/ |
|
164 |
public function put_contents($file, $contents, $mode = false ) { |
|
0 | 165 |
$temp = wp_tempnam( $file ); |
166 |
if ( ! $temphandle = @fopen($temp, 'w+') ) { |
|
167 |
unlink($temp); |
|
168 |
return false; |
|
169 |
} |
|
170 |
||
171 |
// The FTP class uses string functions internally during file download/upload |
|
172 |
mbstring_binary_safe_encoding(); |
|
173 |
||
174 |
$bytes_written = fwrite( $temphandle, $contents ); |
|
175 |
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) { |
|
176 |
fclose( $temphandle ); |
|
177 |
unlink( $temp ); |
|
178 |
||
179 |
reset_mbstring_encoding(); |
|
180 |
||
181 |
return false; |
|
182 |
} |
|
183 |
||
184 |
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to |
|
185 |
||
186 |
$ret = $this->ftp->fput($file, $temphandle); |
|
187 |
||
188 |
reset_mbstring_encoding(); |
|
189 |
||
190 |
fclose($temphandle); |
|
191 |
unlink($temp); |
|
192 |
||
193 |
$this->chmod($file, $mode); |
|
194 |
||
195 |
return $ret; |
|
196 |
} |
|
197 |
||
7
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 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* @return string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
*/ |
5 | 202 |
public function cwd() { |
0 | 203 |
$cwd = $this->ftp->pwd(); |
204 |
if ( $cwd ) |
|
205 |
$cwd = trailingslashit($cwd); |
|
206 |
return $cwd; |
|
207 |
} |
|
208 |
||
7
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 |
* @param string $file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
*/ |
5 | 214 |
public function chdir($file) { |
0 | 215 |
return $this->ftp->chdir($file); |
216 |
} |
|
217 |
||
5 | 218 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* |
5 | 220 |
* @param string $file |
221 |
* @param int|bool $mode |
|
222 |
* @param bool $recursive |
|
223 |
* @return bool |
|
224 |
*/ |
|
225 |
public function chmod($file, $mode = false, $recursive = false ) { |
|
0 | 226 |
if ( ! $mode ) { |
227 |
if ( $this->is_file($file) ) |
|
228 |
$mode = FS_CHMOD_FILE; |
|
229 |
elseif ( $this->is_dir($file) ) |
|
230 |
$mode = FS_CHMOD_DIR; |
|
231 |
else |
|
232 |
return false; |
|
233 |
} |
|
234 |
||
235 |
// chmod any sub-objects if recursive. |
|
236 |
if ( $recursive && $this->is_dir($file) ) { |
|
237 |
$filelist = $this->dirlist($file); |
|
238 |
foreach ( (array)$filelist as $filename => $filemeta ) |
|
239 |
$this->chmod($file . '/' . $filename, $mode, $recursive); |
|
240 |
} |
|
241 |
||
242 |
// chmod the file or directory |
|
243 |
return $this->ftp->chmod($file, $mode); |
|
244 |
} |
|
245 |
||
5 | 246 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* |
5 | 248 |
* @param string $file |
249 |
* @return string |
|
250 |
*/ |
|
251 |
public function owner($file) { |
|
0 | 252 |
$dir = $this->dirlist($file); |
253 |
return $dir[$file]['owner']; |
|
254 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
|
5 | 256 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* |
5 | 258 |
* @param string $file |
259 |
* @return string |
|
260 |
*/ |
|
261 |
public function getchmod($file) { |
|
0 | 262 |
$dir = $this->dirlist($file); |
263 |
return $dir[$file]['permsn']; |
|
264 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
5 | 266 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* |
5 | 268 |
* @param string $file |
269 |
* @return string |
|
270 |
*/ |
|
271 |
public function group($file) { |
|
0 | 272 |
$dir = $this->dirlist($file); |
273 |
return $dir[$file]['group']; |
|
274 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
|
5 | 276 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* @param string $source |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* @param string $destination |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* @param bool $overwrite |
5 | 281 |
* @param int|bool $mode |
282 |
* @return bool |
|
283 |
*/ |
|
284 |
public function copy($source, $destination, $overwrite = false, $mode = false) { |
|
0 | 285 |
if ( ! $overwrite && $this->exists($destination) ) |
286 |
return false; |
|
287 |
||
288 |
$content = $this->get_contents($source); |
|
289 |
if ( false === $content ) |
|
290 |
return false; |
|
291 |
||
292 |
return $this->put_contents($destination, $content, $mode); |
|
293 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
|
5 | 295 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
* |
5 | 297 |
* @param string $source |
298 |
* @param string $destination |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @param bool $overwrite |
5 | 300 |
* @return bool |
301 |
*/ |
|
302 |
public function move($source, $destination, $overwrite = false ) { |
|
0 | 303 |
return $this->ftp->rename($source, $destination); |
304 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
|
5 | 306 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
* |
5 | 308 |
* @param string $file |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
* @param bool $recursive |
5 | 310 |
* @param string $type |
311 |
* @return bool |
|
312 |
*/ |
|
313 |
public function delete($file, $recursive = false, $type = false) { |
|
0 | 314 |
if ( empty($file) ) |
315 |
return false; |
|
316 |
if ( 'f' == $type || $this->is_file($file) ) |
|
317 |
return $this->ftp->delete($file); |
|
318 |
if ( !$recursive ) |
|
319 |
return $this->ftp->rmdir($file); |
|
320 |
||
321 |
return $this->ftp->mdel($file); |
|
322 |
} |
|
323 |
||
5 | 324 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
5 | 326 |
* @param string $file |
327 |
* @return bool |
|
328 |
*/ |
|
329 |
public function exists( $file ) { |
|
0 | 330 |
$list = $this->ftp->nlist( $file ); |
5 | 331 |
|
332 |
if ( empty( $list ) && $this->is_dir( $file ) ) { |
|
333 |
return true; // File is an empty directory. |
|
334 |
} |
|
335 |
||
0 | 336 |
return !empty( $list ); //empty list = no file, so invert. |
5 | 337 |
// Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server. |
0 | 338 |
} |
339 |
||
5 | 340 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* |
5 | 342 |
* @param string $file |
343 |
* @return bool |
|
344 |
*/ |
|
345 |
public function is_file($file) { |
|
0 | 346 |
if ( $this->is_dir($file) ) |
347 |
return false; |
|
348 |
if ( $this->exists($file) ) |
|
349 |
return true; |
|
350 |
return false; |
|
351 |
} |
|
352 |
||
5 | 353 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
* |
5 | 355 |
* @param string $path |
356 |
* @return bool |
|
357 |
*/ |
|
358 |
public function is_dir($path) { |
|
0 | 359 |
$cwd = $this->cwd(); |
360 |
if ( $this->chdir($path) ) { |
|
361 |
$this->chdir($cwd); |
|
362 |
return true; |
|
363 |
} |
|
364 |
return false; |
|
365 |
} |
|
366 |
||
5 | 367 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* |
5 | 369 |
* @param string $file |
370 |
* @return bool |
|
371 |
*/ |
|
372 |
public function is_readable($file) { |
|
0 | 373 |
return true; |
374 |
} |
|
375 |
||
5 | 376 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* |
5 | 378 |
* @param string $file |
379 |
* @return bool |
|
380 |
*/ |
|
381 |
public function is_writable($file) { |
|
0 | 382 |
return true; |
383 |
} |
|
384 |
||
5 | 385 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
5 | 387 |
* @param string $file |
388 |
* @return bool |
|
389 |
*/ |
|
390 |
public function atime($file) { |
|
0 | 391 |
return false; |
392 |
} |
|
393 |
||
5 | 394 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* |
5 | 396 |
* @param string $file |
397 |
* @return int |
|
398 |
*/ |
|
399 |
public function mtime($file) { |
|
0 | 400 |
return $this->ftp->mdtm($file); |
401 |
} |
|
402 |
||
5 | 403 |
/** |
404 |
* @param string $file |
|
405 |
* @return int |
|
406 |
*/ |
|
407 |
public function size($file) { |
|
0 | 408 |
return $this->ftp->filesize($file); |
409 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
|
5 | 411 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
* |
5 | 413 |
* @param string $file |
414 |
* @param int $time |
|
415 |
* @param int $atime |
|
416 |
* @return bool |
|
417 |
*/ |
|
418 |
public function touch($file, $time = 0, $atime = 0 ) { |
|
0 | 419 |
return false; |
420 |
} |
|
421 |
||
5 | 422 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* |
5 | 424 |
* @param string $path |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* @param mixed $chmod |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @param mixed $chown |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param mixed $chgrp |
5 | 428 |
* @return bool |
429 |
*/ |
|
430 |
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { |
|
0 | 431 |
$path = untrailingslashit($path); |
432 |
if ( empty($path) ) |
|
433 |
return false; |
|
434 |
||
435 |
if ( ! $this->ftp->mkdir($path) ) |
|
436 |
return false; |
|
437 |
if ( ! $chmod ) |
|
438 |
$chmod = FS_CHMOD_DIR; |
|
439 |
$this->chmod($path, $chmod); |
|
440 |
return true; |
|
441 |
} |
|
442 |
||
5 | 443 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* @param string $path |
5 | 446 |
* @param bool $recursive |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* @return bool |
5 | 448 |
*/ |
449 |
public function rmdir($path, $recursive = false ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
return $this->delete($path, $recursive); |
0 | 451 |
} |
452 |
||
5 | 453 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* |
5 | 455 |
* @param string $path |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @param bool $include_hidden |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* @param bool $recursive |
5 | 458 |
* @return bool|array |
459 |
*/ |
|
460 |
public function dirlist($path = '.', $include_hidden = true, $recursive = false ) { |
|
0 | 461 |
if ( $this->is_file($path) ) { |
462 |
$limit_file = basename($path); |
|
463 |
$path = dirname($path) . '/'; |
|
464 |
} else { |
|
465 |
$limit_file = false; |
|
466 |
} |
|
467 |
||
468 |
mbstring_binary_safe_encoding(); |
|
469 |
||
470 |
$list = $this->ftp->dirlist($path); |
|
471 |
if ( empty( $list ) && ! $this->exists( $path ) ) { |
|
472 |
||
473 |
reset_mbstring_encoding(); |
|
474 |
||
475 |
return false; |
|
476 |
} |
|
477 |
||
478 |
$ret = array(); |
|
479 |
foreach ( $list as $struc ) { |
|
480 |
||
481 |
if ( '.' == $struc['name'] || '..' == $struc['name'] ) |
|
482 |
continue; |
|
483 |
||
484 |
if ( ! $include_hidden && '.' == $struc['name'][0] ) |
|
485 |
continue; |
|
486 |
||
487 |
if ( $limit_file && $struc['name'] != $limit_file ) |
|
488 |
continue; |
|
489 |
||
490 |
if ( 'd' == $struc['type'] ) { |
|
491 |
if ( $recursive ) |
|
492 |
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); |
|
493 |
else |
|
494 |
$struc['files'] = array(); |
|
495 |
} |
|
496 |
||
497 |
// Replace symlinks formatted as "source -> target" with just the source name |
|
498 |
if ( $struc['islink'] ) |
|
499 |
$struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); |
|
500 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
// Add the Octal representation of the file permissions |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
|
0 | 504 |
$ret[ $struc['name'] ] = $struc; |
505 |
} |
|
506 |
||
507 |
reset_mbstring_encoding(); |
|
508 |
||
509 |
return $ret; |
|
510 |
} |
|
511 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
*/ |
5 | 514 |
public function __destruct() { |
0 | 515 |
$this->ftp->quit(); |
516 |
} |
|
517 |
} |