commit | author | age
|
2207d6
|
1 |
# FTP |
W |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
Works with SFTP/FTP servers. |
|
6 |
|
|
7 |
In order to test the contents of a specific file stored on any remote FTP/SFTP system |
|
8 |
this module downloads a temporary file to the local system. The temporary directory is |
|
9 |
defined by default as ```tests/_data``` to specify a different directory set the tmp config |
|
10 |
option to your chosen path. |
|
11 |
|
|
12 |
Don't forget to create the folder and ensure its writable. |
|
13 |
|
|
14 |
Supported and tested FTP types are: |
|
15 |
|
|
16 |
* FTP |
|
17 |
* SFTP |
|
18 |
|
|
19 |
Connection uses php build in FTP client for FTP, |
|
20 |
connection to SFTP uses [phpseclib](http://phpseclib.sourceforge.net/) pulled in using composer. |
|
21 |
|
|
22 |
For SFTP, add [phpseclib](http://phpseclib.sourceforge.net/) to require list. |
|
23 |
``` |
|
24 |
"require": { |
|
25 |
"phpseclib/phpseclib": "^2.0.14" |
|
26 |
} |
|
27 |
``` |
|
28 |
|
|
29 |
## Status |
|
30 |
|
|
31 |
* Maintainer: **nathanmac** |
|
32 |
* Stability: |
|
33 |
- FTP: **stable** |
|
34 |
- SFTP: **stable** |
|
35 |
* Contact: nathan.macnamara@outlook.com |
|
36 |
|
|
37 |
## Config |
|
38 |
|
|
39 |
* type: ftp - type of connection ftp/sftp (defaults to ftp). |
|
40 |
* host *required* - hostname/ip address of the ftp server. |
|
41 |
* port: 21 - port number for the ftp server |
|
42 |
* timeout: 90 - timeout settings for connecting the ftp server. |
|
43 |
* user: anonymous - user to access ftp server, defaults to anonymous authentication. |
|
44 |
* password - password, defaults to empty for anonymous. |
|
45 |
* key - path to RSA key for sftp. |
|
46 |
* tmp - path to local directory for storing tmp files. |
|
47 |
* passive: true - Turns on or off passive mode (FTP only) |
|
48 |
* cleanup: true - remove tmp files from local directory on completion. |
|
49 |
|
|
50 |
### Example |
|
51 |
#### Example (FTP) |
|
52 |
|
|
53 |
modules: |
|
54 |
enabled: [FTP] |
|
55 |
config: |
|
56 |
FTP: |
|
57 |
type: ftp |
|
58 |
host: '127.0.0.1' |
|
59 |
port: 21 |
|
60 |
timeout: 120 |
|
61 |
user: 'root' |
|
62 |
password: 'root' |
|
63 |
key: ~/.ssh/id_rsa |
|
64 |
tmp: 'tests/_data/ftp' |
|
65 |
passive: true |
|
66 |
cleanup: false |
|
67 |
|
|
68 |
#### Example (SFTP) |
|
69 |
|
|
70 |
modules: |
|
71 |
enabled: [FTP] |
|
72 |
config: |
|
73 |
FTP: |
|
74 |
type: sftp |
|
75 |
host: '127.0.0.1' |
|
76 |
port: 22 |
|
77 |
timeout: 120 |
|
78 |
user: 'root' |
|
79 |
password: 'root' |
|
80 |
key: '' |
|
81 |
tmp: 'tests/_data/ftp' |
|
82 |
cleanup: false |
|
83 |
|
|
84 |
|
|
85 |
This module extends the Filesystem module, file contents methods are inherited from this module. |
|
86 |
|
|
87 |
## Actions |
|
88 |
|
|
89 |
### amInPath |
|
90 |
|
|
91 |
Enters a directory on the ftp system - FTP root directory is used by default |
|
92 |
|
|
93 |
* `param` $path |
|
94 |
|
|
95 |
|
|
96 |
### cleanDir |
|
97 |
|
|
98 |
Erases directory contents on the FTP/SFTP server |
|
99 |
|
|
100 |
``` php |
|
101 |
<?php |
|
102 |
$I->cleanDir('logs'); |
|
103 |
?> |
|
104 |
``` |
|
105 |
|
|
106 |
* `param` $dirname |
|
107 |
|
|
108 |
|
|
109 |
### copyDir |
|
110 |
|
|
111 |
Currently not supported in this module, overwrite inherited method |
|
112 |
|
|
113 |
* `param` $src |
|
114 |
* `param` $dst |
|
115 |
|
|
116 |
|
|
117 |
### deleteDir |
|
118 |
|
|
119 |
Deletes directory with all subdirectories on the remote FTP/SFTP server |
|
120 |
|
|
121 |
``` php |
|
122 |
<?php |
|
123 |
$I->deleteDir('vendor'); |
|
124 |
?> |
|
125 |
``` |
|
126 |
|
|
127 |
* `param` $dirname |
|
128 |
|
|
129 |
|
|
130 |
### deleteFile |
|
131 |
|
|
132 |
Deletes a file on the remote FTP/SFTP system |
|
133 |
|
|
134 |
``` php |
|
135 |
<?php |
|
136 |
$I->deleteFile('composer.lock'); |
|
137 |
?> |
|
138 |
``` |
|
139 |
|
|
140 |
* `param` $filename |
|
141 |
|
|
142 |
|
|
143 |
### deleteThisFile |
|
144 |
|
|
145 |
Deletes a file |
|
146 |
|
|
147 |
|
|
148 |
### dontSeeFileFound |
|
149 |
|
|
150 |
Checks if file does not exist in path on the remote FTP/SFTP system |
|
151 |
|
|
152 |
* `param` $filename |
|
153 |
* `param string` $path |
|
154 |
|
|
155 |
|
|
156 |
### dontSeeFileFoundMatches |
|
157 |
|
|
158 |
Checks if file does not exist in path on the remote FTP/SFTP system, using regular expression as filename. |
|
159 |
DOES NOT OPEN the file when it's exists |
|
160 |
|
|
161 |
* `param` $regex |
|
162 |
* `param string` $path |
|
163 |
|
|
164 |
|
|
165 |
### dontSeeInThisFile |
|
166 |
|
|
167 |
Checks If opened file doesn't contain `text` in it |
|
168 |
|
|
169 |
``` php |
|
170 |
<?php |
|
171 |
$I->openFile('composer.json'); |
|
172 |
$I->dontSeeInThisFile('codeception/codeception'); |
|
173 |
?> |
|
174 |
``` |
|
175 |
|
|
176 |
* `param string` $text |
|
177 |
|
|
178 |
|
|
179 |
### grabDirectory |
|
180 |
|
|
181 |
Grabber method to return current working directory |
|
182 |
|
|
183 |
```php |
|
184 |
<?php |
|
185 |
$pwd = $I->grabDirectory(); |
|
186 |
?> |
|
187 |
``` |
|
188 |
|
|
189 |
* `return` string |
|
190 |
|
|
191 |
|
|
192 |
### grabFileCount |
|
193 |
|
|
194 |
Grabber method for returning file/folders count in directory |
|
195 |
|
|
196 |
```php |
|
197 |
<?php |
|
198 |
$count = $I->grabFileCount(); |
|
199 |
$count = $I->grabFileCount('TEST', false); // Include . .. .thumbs.db |
|
200 |
?> |
|
201 |
``` |
|
202 |
|
|
203 |
* `param string` $path |
|
204 |
* `param bool` $ignore - suppress '.', '..' and '.thumbs.db' |
|
205 |
* `return` int |
|
206 |
|
|
207 |
|
|
208 |
### grabFileList |
|
209 |
|
|
210 |
Grabber method for returning file/folders listing in an array |
|
211 |
|
|
212 |
```php |
|
213 |
<?php |
|
214 |
$files = $I->grabFileList(); |
|
215 |
$count = $I->grabFileList('TEST', false); // Include . .. .thumbs.db |
|
216 |
?> |
|
217 |
``` |
|
218 |
|
|
219 |
* `param string` $path |
|
220 |
* `param bool` $ignore - suppress '.', '..' and '.thumbs.db' |
|
221 |
* `return` array |
|
222 |
|
|
223 |
|
|
224 |
### grabFileModified |
|
225 |
|
|
226 |
Grabber method to return last modified timestamp |
|
227 |
|
|
228 |
```php |
|
229 |
<?php |
|
230 |
$time = $I->grabFileModified('test.txt'); |
|
231 |
?> |
|
232 |
``` |
|
233 |
|
|
234 |
* `param` $filename |
|
235 |
* `return` bool |
|
236 |
|
|
237 |
|
|
238 |
### grabFileSize |
|
239 |
|
|
240 |
Grabber method to return file size |
|
241 |
|
|
242 |
```php |
|
243 |
<?php |
|
244 |
$size = $I->grabFileSize('test.txt'); |
|
245 |
?> |
|
246 |
``` |
|
247 |
|
|
248 |
* `param` $filename |
|
249 |
* `return` bool |
|
250 |
|
|
251 |
|
|
252 |
### loginAs |
|
253 |
|
|
254 |
Change the logged in user mid-way through your test, this closes the |
|
255 |
current connection to the server and initialises and new connection. |
|
256 |
|
|
257 |
On initiation of this modules you are automatically logged into |
|
258 |
the server using the specified config options or defaulted |
|
259 |
to anonymous user if not provided. |
|
260 |
|
|
261 |
``` php |
|
262 |
<?php |
|
263 |
$I->loginAs('user','password'); |
|
264 |
?> |
|
265 |
``` |
|
266 |
|
|
267 |
* `param String` $user |
|
268 |
* `param String` $password |
|
269 |
|
|
270 |
|
|
271 |
### makeDir |
|
272 |
|
|
273 |
Create a directory on the server |
|
274 |
|
|
275 |
``` php |
|
276 |
<?php |
|
277 |
$I->makeDir('vendor'); |
|
278 |
?> |
|
279 |
``` |
|
280 |
|
|
281 |
* `param` $dirname |
|
282 |
|
|
283 |
|
|
284 |
### openFile |
|
285 |
|
|
286 |
Opens a file (downloads from the remote FTP/SFTP system to a tmp directory for processing) |
|
287 |
and stores it's content. |
|
288 |
|
|
289 |
Usage: |
|
290 |
|
|
291 |
``` php |
|
292 |
<?php |
|
293 |
$I->openFile('composer.json'); |
|
294 |
$I->seeInThisFile('codeception/codeception'); |
|
295 |
?> |
|
296 |
``` |
|
297 |
|
|
298 |
* `param` $filename |
|
299 |
|
|
300 |
|
|
301 |
### renameDir |
|
302 |
|
|
303 |
Rename/Move directory on the FTP/SFTP server |
|
304 |
|
|
305 |
``` php |
|
306 |
<?php |
|
307 |
$I->renameDir('vendor', 'vendor_old'); |
|
308 |
?> |
|
309 |
``` |
|
310 |
|
|
311 |
* `param` $dirname |
|
312 |
* `param` $rename |
|
313 |
|
|
314 |
|
|
315 |
### renameFile |
|
316 |
|
|
317 |
Rename/Move file on the FTP/SFTP server |
|
318 |
|
|
319 |
``` php |
|
320 |
<?php |
|
321 |
$I->renameFile('composer.lock', 'composer_old.lock'); |
|
322 |
?> |
|
323 |
``` |
|
324 |
|
|
325 |
* `param` $filename |
|
326 |
* `param` $rename |
|
327 |
|
|
328 |
|
|
329 |
### seeFileContentsEqual |
|
330 |
|
|
331 |
Checks the strict matching of file contents. |
|
332 |
Unlike `seeInThisFile` will fail if file has something more than expected lines. |
|
333 |
Better to use with HEREDOC strings. |
|
334 |
Matching is done after removing "\r" chars from file content. |
|
335 |
|
|
336 |
``` php |
|
337 |
<?php |
|
338 |
$I->openFile('process.pid'); |
|
339 |
$I->seeFileContentsEqual('3192'); |
|
340 |
?> |
|
341 |
``` |
|
342 |
|
|
343 |
* `param string` $text |
|
344 |
|
|
345 |
|
|
346 |
### seeFileFound |
|
347 |
|
|
348 |
Checks if file exists in path on the remote FTP/SFTP system. |
|
349 |
DOES NOT OPEN the file when it's exists |
|
350 |
|
|
351 |
``` php |
|
352 |
<?php |
|
353 |
$I->seeFileFound('UserModel.php','app/models'); |
|
354 |
?> |
|
355 |
``` |
|
356 |
|
|
357 |
* `param` $filename |
|
358 |
* `param string` $path |
|
359 |
|
|
360 |
|
|
361 |
### seeFileFoundMatches |
|
362 |
|
|
363 |
Checks if file exists in path on the remote FTP/SFTP system, using regular expression as filename. |
|
364 |
DOES NOT OPEN the file when it's exists |
|
365 |
|
|
366 |
``` php |
|
367 |
<?php |
|
368 |
$I->seeFileFoundMatches('/^UserModel_([0-9]{6}).php$/','app/models'); |
|
369 |
?> |
|
370 |
``` |
|
371 |
|
|
372 |
* `param` $regex |
|
373 |
* `param string` $path |
|
374 |
|
|
375 |
|
|
376 |
### seeInThisFile |
|
377 |
|
|
378 |
Checks If opened file has `text` in it. |
|
379 |
|
|
380 |
Usage: |
|
381 |
|
|
382 |
``` php |
|
383 |
<?php |
|
384 |
$I->openFile('composer.json'); |
|
385 |
$I->seeInThisFile('codeception/codeception'); |
|
386 |
?> |
|
387 |
``` |
|
388 |
|
|
389 |
* `param string` $text |
|
390 |
|
|
391 |
|
|
392 |
### seeNumberNewLines |
|
393 |
|
|
394 |
Checks If opened file has the `number` of new lines. |
|
395 |
|
|
396 |
Usage: |
|
397 |
|
|
398 |
``` php |
|
399 |
<?php |
|
400 |
$I->openFile('composer.json'); |
|
401 |
$I->seeNumberNewLines(5); |
|
402 |
?> |
|
403 |
``` |
|
404 |
|
|
405 |
* `param int` $number New lines |
|
406 |
|
|
407 |
|
|
408 |
### seeThisFileMatches |
|
409 |
|
|
410 |
Checks that contents of currently opened file matches $regex |
|
411 |
|
|
412 |
* `param string` $regex |
|
413 |
|
|
414 |
|
|
415 |
### writeToFile |
|
416 |
|
|
417 |
Saves contents to tmp file and uploads the FTP/SFTP system. |
|
418 |
Overwrites current file on server if exists. |
|
419 |
|
|
420 |
``` php |
|
421 |
<?php |
|
422 |
$I->writeToFile('composer.json', 'some data here'); |
|
423 |
?> |
|
424 |
``` |
|
425 |
|
|
426 |
* `param` $filename |
|
427 |
* `param` $contents |
|
428 |
|
|
429 |
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.5/src/Codeception/Module/FTP.php">Help us to improve documentation. Edit module reference</a></div> |