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