admin | 62489d5 | 2006-10-27 06:25:51 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
| 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
| 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
| 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
| 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
| 36 | <td><h1>Code Igniter User Guide Version 1.5.0b3</h1></td>
|
| 37 | <td id="breadcrumb_right"><a href="../toc.html">Linear Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | FTP Class
|
| 51 | </td>
|
| 52 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 53 | </tr>
|
| 54 | </table>
|
| 55 | <!-- END BREADCRUMB -->
|
| 56 |
|
| 57 | <br clear="all" />
|
| 58 |
|
| 59 |
|
| 60 | <!-- START CONTENT -->
|
| 61 | <div id="content">
|
| 62 |
|
| 63 |
|
| 64 | <h1>FTP Class</h1>
|
| 65 |
|
admin | 865b4b3 | 2006-10-27 07:33:49 +0000 | [diff] [blame] | 66 | <p>Code Igniter's FTP Class permits files to be uploaded via FTP to your server. It also includes a "mirroring" function
|
| 67 | that permits an local directory to be recreated remotely via FTP.</p>
|
| 68 |
|
| 69 | <h2>Initializing the Class</h2>
|
| 70 |
|
| 71 | <p>Like most other classes in Code Igniter, the FTP class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
|
| 72 |
|
| 73 | <code>$this->load->library('ftp');</code>
|
| 74 | <p>Once loaded, the FTP object will be available using: <dfn>$this->ftp</dfn></p>
|
| 75 |
|
| 76 |
|
| 77 | <h2>Usage Examples</h2>
|
| 78 |
|
| 79 | <p>In this example a connection is opened to the FTP server, and a local file is read and uploaded in ASCII mode. The
|
| 80 | file permissions are set to 755. Note: Setting permissions requires PHP 5.</p>
|
| 81 |
|
| 82 | <code>
|
| 83 | $this->load->library('ftp');<br />
|
| 84 | <br />
|
| 85 | $config['hostname'] = 'ftp.your-site.com';<br />
|
| 86 | $config['username'] = 'your-username';<br />
|
| 87 | $config['password'] = 'your-password';<br />
|
| 88 | $config['debug'] = TRUE;<br />
|
| 89 | <br />
|
| 90 | $this->ftp->connect($config);<br />
|
| 91 | <br />
|
| 92 | $this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);<br />
|
| 93 | <br />
|
| 94 | $this->ftp->close();
|
| 95 |
|
| 96 | </code>
|
| 97 |
|
| 98 |
|
| 99 | <p>In this example a list of files is retrieved from the server.</p>
|
| 100 |
|
| 101 | <code>
|
| 102 | $this->load->library('ftp');<br />
|
| 103 | <br />
|
| 104 | $config['hostname'] = 'ftp.your-site.com';<br />
|
| 105 | $config['username'] = 'your-username';<br />
|
| 106 | $config['password'] = 'your-password';<br />
|
| 107 | $config['debug'] = TRUE;<br />
|
| 108 | <br />
|
| 109 | $this->ftp->connect($config);<br />
|
| 110 | <br />
|
| 111 | $list = $this->ftp->list_files('/public_html/');<br />
|
| 112 | <br />
|
| 113 | print_r($list);<br />
|
| 114 | <br />
|
| 115 | $this->ftp->close();
|
| 116 | </code>
|
| 117 |
|
| 118 | <p>In this example a local directory is mirrored on the server.</p>
|
| 119 |
|
| 120 |
|
| 121 | <code>
|
| 122 | $this->load->library('ftp');<br />
|
| 123 | <br />
|
| 124 | $config['hostname'] = 'ftp.your-site.com';<br />
|
| 125 | $config['username'] = 'your-username';<br />
|
| 126 | $config['password'] = 'your-password';<br />
|
| 127 | $config['debug'] = TRUE;<br />
|
| 128 | <br />
|
| 129 | $this->ftp->connect($config);<br />
|
| 130 | <br />
|
| 131 | $this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');<br />
|
| 132 | <br />
|
| 133 | $this->ftp->close();
|
| 134 | </code>
|
| 135 |
|
| 136 |
|
| 137 | <h1>Function Reference</h1>
|
| 138 |
|
| 139 | <h2>$this->ftp->connect()</h2>
|
| 140 |
|
| 141 | <p>Connects and logs into to the FTP server. Connection preferences are set by passing an array
|
| 142 | to the function, or you can store them in a config file.</p>
|
| 143 |
|
| 144 |
|
| 145 | <p>Here is an example showing how you set preferences manually:</p>
|
| 146 |
|
| 147 | <code>
|
| 148 | $this->load->library('ftp');<br />
|
| 149 | <br />
|
| 150 | $config['hostname'] = 'ftp.your-site.com';<br />
|
| 151 | $config['username'] = 'your-username';<br />
|
| 152 | $config['password'] = 'your-password';<br />
|
| 153 | $config['port'] = 21;<br />
|
| 154 | $config['passive'] = FALSE;<br />
|
| 155 | $config['debug'] = TRUE;<br />
|
| 156 | <br />
|
| 157 | $this->ftp->connect($config);<br />
|
| 158 | </code>
|
| 159 |
|
| 160 | <h3>Setting FTP Preferences in a Config File</h3>
|
| 161 |
|
| 162 | <p>If you prefer you can store your FTP preferences in a config file.
|
| 163 | Simply create a new file called the <var>ftp.php</var>, add the <var>$config</var>
|
| 164 | array in that file. Then save the file at <var>config/ftp.php</var> and it will be used automatically.</p>
|
| 165 |
|
| 166 | <h3>Available connection options:</h3>
|
| 167 |
|
| 168 |
|
| 169 | <ul>
|
| 170 | <li><strong>hostname</strong> - the FTP hostname. Usually something like: <dfn>ftp.some-site.com</dfn></li>
|
| 171 | <li><strong>username</strong> - the FTP username.</li>
|
| 172 | <li><strong>password</strong> - the FTP password.</li>
|
| 173 | <li><strong>port</strong> - The port number. Set to <dfn>21</dfn> by default.</li>
|
| 174 | <li><strong>debug</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to enable debugging to display error messages.</li>
|
| 175 | <li><strong>passive</strong> - <kbd>TRUE/FALSE</kbd> (boolean). Whether to use passive mode. Passive is set automatically by default.</li>
|
| 176 | </ul>
|
| 177 |
|
| 178 |
|
| 179 | <h2>$this->ftp->sconnect()</h2>
|
| 180 |
|
| 181 | <p>Secure FTP connect. This function is identical to the function above, except that it initiates a secure connection.</p>
|
| 182 |
|
| 183 |
|
| 184 | <h2>$this->ftp->upload()</h2>
|
| 185 |
|
admin | 631f17b | 2006-10-27 07:41:28 +0000 | [diff] [blame] | 186 | <p>Uploads a file to your server. You must supply the local path and the remote path, and you can optionally set the mode and permissions.
|
admin | 865b4b3 | 2006-10-27 07:33:49 +0000 | [diff] [blame] | 187 | Example:</p>
|
| 188 |
|
| 189 |
|
| 190 | <code>$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);</code>
|
| 191 |
|
| 192 | <p><strong>Mode options are:</strong> <kbd>ascii</kbd>, <kbd>binary</kbd>, and <kbd>auto</kbd> (the default). If
|
| 193 | <kbd>auto</kbd> is used it will base the mode on the file extension of the source file.</p>
|
| 194 |
|
| 195 | <p>Permissions are available if you are running PHP 5 and can be passed as an <kbd>octal</kbd> value in the fourth parameter.</p>
|
| 196 |
|
| 197 |
|
| 198 | <h2>$this->ftp->mkdir()</h2>
|
| 199 |
|
| 200 | <p>Lets you create a directory on your server. Supply the path ending in the folder name you wish to create, with a trailing slash:</p>
|
| 201 |
|
| 202 | <code>
|
| 203 | // Creates a folder named "bar"<br />
|
| 204 | $this->ftp->mkdir('/public_html/foo/bar/');
|
| 205 | </code>
|
| 206 |
|
| 207 |
|
| 208 | <h2>$this->ftp->chmod()</h2>
|
| 209 |
|
| 210 | <p>Permits you to set file permissions. Supply the path to the file or folder you wish to alter permissions on:</p>
|
| 211 |
|
| 212 | <code>
|
| 213 | // Chmod "bar" to 777<br />
|
| 214 | $this->ftp->chmod('/public_html/foo/bar/', 0777);
|
| 215 | </code>
|
| 216 |
|
| 217 |
|
| 218 | <h2>$this->ftp->list_files()</h2>
|
| 219 | <p>Permits you to retrieve a list of files on your server returned as an <dfn>array</dfn>. You must supply
|
| 220 | the path to the desired directory.</p>
|
| 221 |
|
| 222 | <code>
|
| 223 | $list = $this->ftp->list_files('/public_html/');<br />
|
| 224 | <br />
|
| 225 | print_r($list);
|
| 226 | </code>
|
| 227 |
|
| 228 |
|
| 229 | <h2>$this->ftp->mirror()</h2>
|
| 230 |
|
| 231 | <p>Recursively reads a folder and everything it contains (including sub-folders) and creates a
|
| 232 | mirror via FTP based on it. Whatever the directory structure of the original file path will be recreated on the server.
|
| 233 | You must supply a source path and a destination path:</p>
|
| 234 |
|
| 235 | <code>
|
| 236 | $this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');
|
| 237 | </code>
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 | <h2>$this->ftp->close();</h2>
|
| 242 | <p>Closes the connection to your server. It's recommended that you use this when you are finished uploading.</p>
|
| 243 |
|
| 244 |
|
admin | 62489d5 | 2006-10-27 06:25:51 +0000 | [diff] [blame] | 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 | </div>
|
| 252 | <!-- END CONTENT -->
|
| 253 |
|
| 254 |
|
| 255 | <div id="footer">
|
| 256 | <p>
|
| 257 | Previous Topic: <a href="uploading.html">File Uploading Class</a>
|
| 258 | ·
|
| 259 | <a href="#top">Top of Page</a> ·
|
| 260 | <a href="../index.html">User Guide Home</a> ·
|
| 261 | Next Topic: <a href="table.html">HTML Table Class</a>
|
| 262 | <p>
|
| 263 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 264 | </div>
|
| 265 |
|
| 266 | </body>
|
| 267 | </html> |