Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ######### |
| 2 | FTP Class |
| 3 | ######### |
| 4 | |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 5 | CodeIgniter's FTP Class permits files to be transferred to a remote |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 6 | server. Remote files can also be moved, renamed, and deleted. The FTP |
| 7 | class also includes a "mirroring" function that permits an entire local |
| 8 | directory to be recreated remotely via FTP. |
| 9 | |
| 10 | .. note:: SFTP and SSL FTP protocols are not supported, only standard |
| 11 | FTP. |
| 12 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 13 | .. contents:: |
| 14 | :local: |
| 15 | |
| 16 | .. raw:: html |
| 17 | |
| 18 | <div class="custom-index container"></div> |
| 19 | |
| 20 | ************************** |
| 21 | Working with the FTP Class |
| 22 | ************************** |
| 23 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 24 | Initializing the Class |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 25 | ====================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 26 | |
| 27 | Like most other classes in CodeIgniter, the FTP class is initialized in |
| 28 | your controller using the $this->load->library function:: |
| 29 | |
| 30 | $this->load->library('ftp'); |
| 31 | |
| 32 | Once loaded, the FTP object will be available using: $this->ftp |
| 33 | |
| 34 | Usage Examples |
| 35 | ============== |
| 36 | |
| 37 | In this example a connection is opened to the FTP server, and a local |
| 38 | file is read and uploaded in ASCII mode. The file permissions are set to |
vlakoff | a36fd63 | 2012-06-27 02:46:19 +0200 | [diff] [blame] | 39 | 755. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 40 | :: |
| 41 | |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 42 | $this->load->library('ftp'); |
| 43 | |
| 44 | $config['hostname'] = 'ftp.example.com'; |
| 45 | $config['username'] = 'your-username'; |
| 46 | $config['password'] = 'your-password'; |
| 47 | $config['debug'] = TRUE; |
| 48 | |
| 49 | $this->ftp->connect($config); |
| 50 | |
| 51 | $this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775); |
| 52 | |
| 53 | $this->ftp->close(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 54 | |
| 55 | In this example a list of files is retrieved from the server. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | :: |
| 57 | |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 58 | $this->load->library('ftp'); |
| 59 | |
| 60 | $config['hostname'] = 'ftp.example.com'; |
| 61 | $config['username'] = 'your-username'; |
| 62 | $config['password'] = 'your-password'; |
| 63 | $config['debug'] = TRUE; |
| 64 | |
| 65 | $this->ftp->connect($config); |
| 66 | |
| 67 | $list = $this->ftp->list_files('/public_html/'); |
| 68 | |
| 69 | print_r($list); |
| 70 | |
| 71 | $this->ftp->close(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 72 | |
| 73 | In this example a local directory is mirrored on the server. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 74 | :: |
| 75 | |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 76 | $this->load->library('ftp'); |
| 77 | |
| 78 | $config['hostname'] = 'ftp.example.com'; |
| 79 | $config['username'] = 'your-username'; |
| 80 | $config['password'] = 'your-password'; |
| 81 | $config['debug'] = TRUE; |
| 82 | |
| 83 | $this->ftp->connect($config); |
| 84 | |
| 85 | $this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/'); |
| 86 | |
| 87 | $this->ftp->close(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 88 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 89 | *************** |
| 90 | Class Reference |
| 91 | *************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 92 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 93 | .. php:class:: CI_FTP |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 94 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 95 | .. php:method:: connect([$config = array()]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 96 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 97 | :param array $config: Connection values |
| 98 | :returns: TRUE on success, FALSE on failure |
| 99 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 100 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 101 | Connects and logs into to the FTP server. Connection preferences are set |
| 102 | by passing an array to the function, or you can store them in a config |
| 103 | file. |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 104 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 105 | Here is an example showing how you set preferences manually:: |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 106 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 107 | $this->load->library('ftp'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 108 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 109 | $config['hostname'] = 'ftp.example.com'; |
| 110 | $config['username'] = 'your-username'; |
| 111 | $config['password'] = 'your-password'; |
| 112 | $config['port'] = 21; |
| 113 | $config['passive'] = FALSE; |
| 114 | $config['debug'] = TRUE; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 115 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 116 | $this->ftp->connect($config); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 117 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 118 | **Setting FTP Preferences in a Config File** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 119 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 120 | If you prefer you can store your FTP preferences in a config file. |
| 121 | Simply create a new file called the ftp.php, add the $config array in |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 122 | that file. Then save the file at *application/config/ftp.php* and it |
| 123 | will be used automatically. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 124 | |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 125 | **Available connection options** |
| 126 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 127 | ============== =============== ============================================================================= |
| 128 | Option name Default value Description |
| 129 | ============== =============== ============================================================================= |
| 130 | **hostname** n/a FTP hostname (usually something like: ftp.example.com) |
| 131 | **username** n/a FTP username |
| 132 | **password** n/a FTP password |
| 133 | **port** 21 FTP server port number |
| 134 | **debug** FALSE TRUE/FALSE (boolean): Whether to enable debugging to display error messages |
| 135 | **passive** TRUE TRUE/FALSE (boolean): Whether to use passive mode |
| 136 | ============== =============== ============================================================================= |
Derek Jones | b799a0b | 2013-08-06 15:38:21 -0700 | [diff] [blame] | 137 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 138 | .. php:method:: upload($locpath, $rempath[, $mode = 'auto'[, $permissions = NULL]]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 139 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 140 | :param string $locpath: Local file path |
| 141 | :param string $rempath: Remote file path |
| 142 | :param string $mode: FTP mode, defaults to 'auto' (options are: 'auto', 'binary', 'ascii') |
| 143 | :param int $permissions: File permissions (octal) |
| 144 | :returns: TRUE on success, FALSE on failure |
| 145 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 146 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 147 | Uploads a file to your server. You must supply the local path and the |
| 148 | remote path, and you can optionally set the mode and permissions. |
| 149 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 150 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 151 | $this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 152 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 153 | If 'auto' mode is used it will base the mode on the file extension of the source file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 154 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 155 | If set, permissions have to be passed as an octal value. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 156 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 157 | .. php:method:: download($rempath, $locpath[, $mode = 'auto']) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 158 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 159 | :param string $rempath: Remote file path |
| 160 | :param string $locpath: Local file path |
| 161 | :param string $mode: FTP mode, defaults to 'auto' (options are: 'auto', 'binary', 'ascii') |
| 162 | :returns: TRUE on success, FALSE on failure |
| 163 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 164 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 165 | Downloads a file from your server. You must supply the remote path and |
| 166 | the local path, and you can optionally set the mode. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 167 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 168 | $this->ftp->download('/public_html/myfile.html', '/local/path/to/myfile.html', 'ascii'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 169 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 170 | If 'auto' mode is used it will base the mode on the file extension of the source file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 171 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 172 | Returns FALSE if the download does not execute successfully |
| 173 | (including if PHP does not have permission to write the local file). |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 174 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 175 | .. php:method:: rename($old_file, $new_file[, $move = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 176 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 177 | :param string $old_file: Old file name |
| 178 | :param string $new_file: New file name |
| 179 | :param bool $move: Whether a move is being performed |
| 180 | :returns: TRUE on success, FALSE on failure |
| 181 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 182 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 183 | Permits you to rename a file. Supply the source file name/path and the new file name/path. |
| 184 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 185 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 186 | // Renames green.html to blue.html |
| 187 | $this->ftp->rename('/public_html/foo/green.html', '/public_html/foo/blue.html'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 188 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 189 | .. php:method:: move($old_file, $new_file) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 190 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 191 | :param string $old_file: Old file name |
| 192 | :param string $new_file: New file name |
| 193 | :returns: TRUE on success, FALSE on failure |
| 194 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 195 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 196 | Lets you move a file. Supply the source and destination paths:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 197 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 198 | // Moves blog.html from "joe" to "fred" |
| 199 | $this->ftp->move('/public_html/joe/blog.html', '/public_html/fred/blog.html'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 200 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 201 | .. note:: If the destination file name is different the file will be renamed. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 202 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 203 | .. php:method:: delete_file($filepath) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 204 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 205 | :param string $filepath: Path to file to delete |
| 206 | :returns: TRUE on success, FALSE on failure |
| 207 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 208 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 209 | Lets you delete a file. Supply the source path with the file name. |
| 210 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 211 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 212 | $this->ftp->delete_file('/public_html/joe/blog.html'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 213 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 214 | .. php:method:: delete_dir($filepath) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 215 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 216 | :param string $filepath: Path to directory to delete |
| 217 | :returns: TRUE on success, FALSE on failure |
| 218 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 219 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 220 | Lets you delete a directory and everything it contains. Supply the |
| 221 | source path to the directory with a trailing slash. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 222 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 223 | .. important:: Be VERY careful with this method! |
| 224 | It will recursively delete **everything** within the supplied path, |
| 225 | including sub-folders and all files. Make absolutely sure your path |
| 226 | is correct. Try using ``list_files()`` first to verify that your path is correct. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 227 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 228 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 229 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 230 | $this->ftp->delete_dir('/public_html/path/to/folder/'); |
Derek Jones | 5b8ebce | 2011-10-05 16:00:50 -0500 | [diff] [blame] | 231 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 232 | .. php:method:: list_files([$path = '.']) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 233 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 234 | :param string $path: Directory path |
| 235 | :returns: An array list of files or FALSE on failure |
| 236 | :rtype: array |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 237 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 238 | Permits you to retrieve a list of files on your server returned as an |
| 239 | array. You must supply the path to the desired directory. |
| 240 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 241 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 242 | $list = $this->ftp->list_files('/public_html/'); |
| 243 | print_r($list); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 244 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 245 | .. php:method:: mirror($locpath, $rempath) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 246 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 247 | :param string $locpath: Local path |
| 248 | :param string $rempath: Remote path |
| 249 | :returns: TRUE on success, FALSE on failure |
| 250 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 251 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 252 | Recursively reads a local folder and everything it contains (including |
| 253 | sub-folders) and creates a mirror via FTP based on it. Whatever the |
| 254 | directory structure of the original file path will be recreated on the |
| 255 | server. You must supply a source path and a destination path:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 256 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 257 | $this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 258 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 259 | .. php:method:: mkdir($path[, $permissions = NULL]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 260 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 261 | :param string $path: Path to directory to create |
| 262 | :param int $permissions: Permissions (octal) |
| 263 | :returns: TRUE on success, FALSE on failure |
| 264 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 265 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 266 | Lets you create a directory on your server. Supply the path ending in |
| 267 | the folder name you wish to create, with a trailing slash. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 268 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 269 | Permissions can be set by passing an octal value in the second parameter. |
| 270 | :: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 271 | |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 272 | // Creates a folder named "bar" |
Andrey Andreev | 4596574 | 2014-08-27 20:40:11 +0300 | [diff] [blame] | 273 | $this->ftp->mkdir('/public_html/foo/bar/', 0755); |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 274 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 275 | .. php:method:: chmod($path, $perm) |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 276 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 277 | :param string $path: Path to alter permissions for |
| 278 | :param int $perm: Permissions (octal) |
| 279 | :returns: TRUE on success, FALSE on failure |
| 280 | :rtype: bool |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 281 | |
| 282 | Permits you to set file permissions. Supply the path to the file or |
| 283 | directory you wish to alter permissions on:: |
| 284 | |
Andrey Andreev | 4596574 | 2014-08-27 20:40:11 +0300 | [diff] [blame] | 285 | // Chmod "bar" to 755 |
| 286 | $this->ftp->chmod('/public_html/foo/bar/', 0755); |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 287 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 288 | .. php:method:: changedir($path[, $suppress_debug = FALSE]) |
Andrey Andreev | a322989 | 2014-01-03 17:35:52 +0200 | [diff] [blame] | 289 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 290 | :param string $path: Directory path |
| 291 | :param bool $suppress_debug: Whether to turn off debug messages for this command |
| 292 | :returns: TRUE on success, FALSE on failure |
| 293 | :rtype: bool |
Andrey Andreev | a322989 | 2014-01-03 17:35:52 +0200 | [diff] [blame] | 294 | |
| 295 | Changes the current working directory to the specified path. |
| 296 | |
| 297 | The ``$suppress_debug`` parameter is useful in case you want to use this method |
| 298 | as an ``is_dir()`` alternative for FTP. |
| 299 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 300 | .. php:method:: close() |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 301 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 302 | :returns: TRUE on success, FALSE on failure |
| 303 | :rtype: bool |
Andrey Andreev | eb21ac8 | 2014-01-03 17:27:29 +0200 | [diff] [blame] | 304 | |
| 305 | Closes the connection to your server. It's recommended that you use this |
| 306 | when you are finished uploading. |