152
* @param string $file
153
* @return string|false
147
155
public function get_contents( $file ) {
148
156
$file = ltrim($file, '/');
149
157
return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);
161
* @param string $file
152
164
public function get_contents_array($file) {
153
165
$file = ltrim($file, '/');
154
166
return file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
170
* @param string $file
171
* @param string $contents
172
* @param bool|int $mode
157
175
public function put_contents($file, $contents, $mode = false ) {
158
176
$ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ), $contents );
175
197
public function chdir($dir) {
176
198
return $this->run_command('cd ' . $dir, true);
202
* @param string $file
203
* @param string $group
204
* @param bool $recursive
179
206
public function chgrp($file, $group, $recursive = false ) {
180
207
if ( ! $this->exists($file) )
184
211
return $this->run_command(sprintf('chgrp -R %s %s', escapeshellarg($group), escapeshellarg($file)), true);
215
* @param string $file
217
* @param bool $recursive
187
220
public function chmod($file, $mode = false, $recursive = false) {
188
221
if ( ! $this->exists($file) )
210
* @param string $file Path to the file.
211
* @param mixed $owner A user name or number.
212
* @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False.
213
* @return bool Returns true on success or false on failure.
243
* @param string $file Path to the file.
244
* @param string|int $owner A user name or number.
245
* @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False.
246
* @return bool|string Returns true on success or false on failure.
215
248
public function chown( $file, $owner, $recursive = false ) {
216
249
if ( ! $this->exists($file) )
220
253
return $this->run_command(sprintf('chown -R %s %s', escapeshellarg($owner), escapeshellarg($file)), true);
257
* @param string $file
258
* @return string|false
223
260
public function owner($file) {
224
261
$owneruid = @fileowner('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
225
262
if ( ! $owneruid )
229
266
$ownerarray = posix_getpwuid($owneruid);
230
267
return $ownerarray['name'];
270
* @param string $file
233
273
public function getchmod($file) {
234
274
return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ) ) ), -3 );
278
* @param string $file
279
* @return string|false
237
281
public function group($file) {
238
282
$gid = @filegroup('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
244
288
return $grouparray['name'];
292
* @param string $source
293
* @param string $destination
294
* @param bool $overwrite
295
* @param int|bool $mode
247
298
public function copy($source, $destination, $overwrite = false, $mode = false) {
248
299
if ( ! $overwrite && $this->exists($destination) )
253
304
return $this->put_contents($destination, $content, $mode);
308
* @param string $source
309
* @param string $destination
310
* @param bool $overwrite
256
313
public function move($source, $destination, $overwrite = false) {
257
return @ssh2_sftp_rename($this->link, $source, $destination);
314
return @ssh2_sftp_rename( $this->sftp_link, $source, $destination );
318
* @param string $file
319
* @param bool $recursive
320
* @param string|bool $type
260
323
public function delete($file, $recursive = false, $type = false) {
261
324
if ( 'f' == $type || $this->is_file($file) )
262
325
return ssh2_sftp_unlink($this->sftp_link, $file);
271
334
return ssh2_sftp_rmdir($this->sftp_link, $file);
338
* @param string $file
274
341
public function exists($file) {
275
342
$file = ltrim($file, '/');
276
343
return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file);
346
* @param string $file
279
349
public function is_file($file) {
280
350
$file = ltrim($file, '/');
281
351
return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
354
* @param string $path
284
357
public function is_dir($path) {
285
358
$path = ltrim($path, '/');
286
359
return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path);
362
* @param string $file
289
365
public function is_readable($file) {
290
366
$file = ltrim($file, '/');
291
367
return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file);
370
* @param string $file
294
373
public function is_writable($file) {
295
374
$file = ltrim($file, '/');
296
375
return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file);
378
* @param string $file
299
381
public function atime($file) {
300
382
$file = ltrim($file, '/');
301
383
return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
387
* @param string $file
304
390
public function mtime($file) {
305
391
$file = ltrim($file, '/');
306
392
return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
396
* @param string $file
309
399
public function size($file) {
310
400
$file = ltrim($file, '/');
311
401
return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file);
405
* @param string $file
314
409
public function touch($file, $time = 0, $atime = 0) {
315
410
//Not implemented.
414
* @param string $path
415
* @param mixed $chmod
416
* @param mixed $chown
417
* @param mixed $chgrp
318
420
public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
319
421
$path = untrailingslashit($path);
320
422
if ( empty($path) )
437
* @param string $path
438
* @param bool $recursive
334
441
public function rmdir($path, $recursive = false) {
335
442
return $this->delete($path, $recursive);
446
* @param string $path
447
* @param bool $include_hidden
448
* @param bool $recursive
338
451
public function dirlist($path, $include_hidden = true, $recursive = false) {
339
452
if ( $this->is_file($path) ) {
340
453
$limit_file = basename($path);