PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.0
Defender Security – Malware Scanner, Login Security & Firewall v5.6.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / ftp.php

ftp.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.0, at vendor/thecodingmachine/safe/generated/ftp.php

497 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\FtpException;
6
7 /**
8 * Sends an ALLO command to the remote FTP server to
9 * allocate space for a file to be uploaded.
10 *
11 * @param resource $ftp_stream The link identifier of the FTP connection.
12 * @param int $filesize The number of bytes to allocate.
13 * @param string $result A textual representation of the servers response will be returned by
14 * reference in result if a variable is provided.
15 * @throws FtpException
16 *
17 */
18 function ftp_alloc($ftp_stream, int $filesize, string &$result = null): void
19 {
20 error_clear_last();
21 $result = \ftp_alloc($ftp_stream, $filesize, $result);
22 if ($result === false) {
23 throw FtpException::createFromPhpError();
24 }
25 }
26
27
28 /**
29 *
30 *
31 * @param resource $ftp
32 * @param string $remote_file
33 * @param string $local_file
34 * @param int $mode
35 * @throws FtpException
36 *
37 */
38 function ftp_append($ftp, string $remote_file, string $local_file, int $mode = FTP_BINARY): void
39 {
40 error_clear_last();
41 $result = \ftp_append($ftp, $remote_file, $local_file, $mode);
42 if ($result === false) {
43 throw FtpException::createFromPhpError();
44 }
45 }
46
47
48 /**
49 * Changes to the parent directory.
50 *
51 * @param resource $ftp_stream The link identifier of the FTP connection.
52 * @throws FtpException
53 *
54 */
55 function ftp_cdup($ftp_stream): void
56 {
57 error_clear_last();
58 $result = \ftp_cdup($ftp_stream);
59 if ($result === false) {
60 throw FtpException::createFromPhpError();
61 }
62 }
63
64
65 /**
66 * Changes the current directory to the specified one.
67 *
68 * @param resource $ftp_stream The link identifier of the FTP connection.
69 * @param string $directory The target directory.
70 * @throws FtpException
71 *
72 */
73 function ftp_chdir($ftp_stream, string $directory): void
74 {
75 error_clear_last();
76 $result = \ftp_chdir($ftp_stream, $directory);
77 if ($result === false) {
78 throw FtpException::createFromPhpError();
79 }
80 }
81
82
83 /**
84 * Sets the permissions on the specified remote file to
85 * mode.
86 *
87 * @param resource $ftp_stream The link identifier of the FTP connection.
88 * @param int $mode The new permissions, given as an octal value.
89 * @param string $filename The remote file.
90 * @return int Returns the new file permissions on success.
91 * @throws FtpException
92 *
93 */
94 function ftp_chmod($ftp_stream, int $mode, string $filename): int
95 {
96 error_clear_last();
97 $result = \ftp_chmod($ftp_stream, $mode, $filename);
98 if ($result === false) {
99 throw FtpException::createFromPhpError();
100 }
101 return $result;
102 }
103
104
105 /**
106 * ftp_close closes the given link identifier
107 * and releases the resource.
108 *
109 * @param resource $ftp_stream The link identifier of the FTP connection.
110 * @throws FtpException
111 *
112 */
113 function ftp_close($ftp_stream): void
114 {
115 error_clear_last();
116 $result = \ftp_close($ftp_stream);
117 if ($result === false) {
118 throw FtpException::createFromPhpError();
119 }
120 }
121
122
123 /**
124 * ftp_connect opens an FTP connection to the
125 * specified host.
126 *
127 * @param string $host The FTP server address. This parameter shouldn't have any trailing
128 * slashes and shouldn't be prefixed with ftp://.
129 * @param int $port This parameter specifies an alternate port to connect to. If it is
130 * omitted or set to zero, then the default FTP port, 21, will be used.
131 * @param int $timeout This parameter specifies the timeout in seconds for all subsequent network operations.
132 * If omitted, the default value is 90 seconds. The timeout can be changed and
133 * queried at any time with ftp_set_option and
134 * ftp_get_option.
135 * @return resource Returns a FTP stream on success.
136 * @throws FtpException
137 *
138 */
139 function ftp_connect(string $host, int $port = 21, int $timeout = 90)
140 {
141 error_clear_last();
142 $result = \ftp_connect($host, $port, $timeout);
143 if ($result === false) {
144 throw FtpException::createFromPhpError();
145 }
146 return $result;
147 }
148
149
150 /**
151 * ftp_delete deletes the file specified by
152 * path from the FTP server.
153 *
154 * @param resource $ftp_stream The link identifier of the FTP connection.
155 * @param string $path The file to delete.
156 * @throws FtpException
157 *
158 */
159 function ftp_delete($ftp_stream, string $path): void
160 {
161 error_clear_last();
162 $result = \ftp_delete($ftp_stream, $path);
163 if ($result === false) {
164 throw FtpException::createFromPhpError();
165 }
166 }
167
168
169 /**
170 * ftp_fget retrieves remote_file
171 * from the FTP server, and writes it to the given file pointer.
172 *
173 * @param resource $ftp_stream The link identifier of the FTP connection.
174 * @param resource $handle An open file pointer in which we store the data.
175 * @param string $remote_file The remote file path.
176 * @param int $mode The transfer mode. Must be either FTP_ASCII or
177 * FTP_BINARY.
178 * @param int $resumepos The position in the remote file to start downloading from.
179 * @throws FtpException
180 *
181 */
182 function ftp_fget($ftp_stream, $handle, string $remote_file, int $mode = FTP_BINARY, int $resumepos = 0): void
183 {
184 error_clear_last();
185 $result = \ftp_fget($ftp_stream, $handle, $remote_file, $mode, $resumepos);
186 if ($result === false) {
187 throw FtpException::createFromPhpError();
188 }
189 }
190
191
192 /**
193 * ftp_fput uploads the data from a file pointer
194 * to a remote file on the FTP server.
195 *
196 * @param resource $ftp_stream The link identifier of the FTP connection.
197 * @param string $remote_file The remote file path.
198 * @param resource $handle An open file pointer on the local file. Reading stops at end of file.
199 * @param int $mode The transfer mode. Must be either FTP_ASCII or
200 * FTP_BINARY.
201 * @param int $startpos The position in the remote file to start uploading to.
202 * @throws FtpException
203 *
204 */
205 function ftp_fput($ftp_stream, string $remote_file, $handle, int $mode = FTP_BINARY, int $startpos = 0): void
206 {
207 error_clear_last();
208 $result = \ftp_fput($ftp_stream, $remote_file, $handle, $mode, $startpos);
209 if ($result === false) {
210 throw FtpException::createFromPhpError();
211 }
212 }
213
214
215 /**
216 * ftp_get retrieves a remote file from the FTP server,
217 * and saves it into a local file.
218 *
219 * @param resource $ftp_stream The link identifier of the FTP connection.
220 * @param string $local_file The local file path (will be overwritten if the file already exists).
221 * @param string $remote_file The remote file path.
222 * @param int $mode The transfer mode. Must be either FTP_ASCII or
223 * FTP_BINARY.
224 * @param int $resumepos The position in the remote file to start downloading from.
225 * @throws FtpException
226 *
227 */
228 function ftp_get($ftp_stream, string $local_file, string $remote_file, int $mode = FTP_BINARY, int $resumepos = 0): void
229 {
230 error_clear_last();
231 $result = \ftp_get($ftp_stream, $local_file, $remote_file, $mode, $resumepos);
232 if ($result === false) {
233 throw FtpException::createFromPhpError();
234 }
235 }
236
237
238 /**
239 * Logs in to the given FTP stream.
240 *
241 * @param resource $ftp_stream The link identifier of the FTP connection.
242 * @param string $username The username (USER).
243 * @param string $password The password (PASS).
244 * @throws FtpException
245 *
246 */
247 function ftp_login($ftp_stream, string $username, string $password): void
248 {
249 error_clear_last();
250 $result = \ftp_login($ftp_stream, $username, $password);
251 if ($result === false) {
252 throw FtpException::createFromPhpError();
253 }
254 }
255
256
257 /**
258 * Creates the specified directory on the FTP server.
259 *
260 * @param resource $ftp_stream The link identifier of the FTP connection.
261 * @param string $directory The name of the directory that will be created.
262 * @return string Returns the newly created directory name on success.
263 * @throws FtpException
264 *
265 */
266 function ftp_mkdir($ftp_stream, string $directory): string
267 {
268 error_clear_last();
269 $result = \ftp_mkdir($ftp_stream, $directory);
270 if ($result === false) {
271 throw FtpException::createFromPhpError();
272 }
273 return $result;
274 }
275
276
277 /**
278 *
279 *
280 * @param resource $ftp_stream The link identifier of the FTP connection.
281 * @param string $directory The directory to be listed.
282 * @return array Returns an array of arrays with file infos from the specified directory on success.
283 * @throws FtpException
284 *
285 */
286 function ftp_mlsd($ftp_stream, string $directory): array
287 {
288 error_clear_last();
289 $result = \ftp_mlsd($ftp_stream, $directory);
290 if ($result === false) {
291 throw FtpException::createFromPhpError();
292 }
293 return $result;
294 }
295
296
297 /**
298 *
299 *
300 * @param resource $ftp_stream The link identifier of the FTP connection.
301 * @param string $directory The directory to be listed. This parameter can also include arguments, eg.
302 * ftp_nlist($conn_id, "-la /your/dir");
303 * Note that this parameter isn't escaped so there may be some issues with
304 * filenames containing spaces and other characters.
305 * @return array Returns an array of filenames from the specified directory on success.
306 * @throws FtpException
307 *
308 */
309 function ftp_nlist($ftp_stream, string $directory): array
310 {
311 error_clear_last();
312 $result = \ftp_nlist($ftp_stream, $directory);
313 if ($result === false) {
314 throw FtpException::createFromPhpError();
315 }
316 return $result;
317 }
318
319
320 /**
321 * ftp_pasv turns on or off passive mode. In
322 * passive mode, data connections are initiated by the client,
323 * rather than by the server.
324 * It may be needed if the client is behind firewall.
325 *
326 * Please note that ftp_pasv can only be called after a
327 * successful login or otherwise it will fail.
328 *
329 * @param resource $ftp_stream The link identifier of the FTP connection.
330 * @param bool $pasv If TRUE, the passive mode is turned on, else it's turned off.
331 * @throws FtpException
332 *
333 */
334 function ftp_pasv($ftp_stream, bool $pasv): void
335 {
336 error_clear_last();
337 $result = \ftp_pasv($ftp_stream, $pasv);
338 if ($result === false) {
339 throw FtpException::createFromPhpError();
340 }
341 }
342
343
344 /**
345 * ftp_put stores a local file on the FTP server.
346 *
347 * @param resource $ftp_stream The link identifier of the FTP connection.
348 * @param string $remote_file The remote file path.
349 * @param string $local_file The local file path.
350 * @param int $mode The transfer mode. Must be either FTP_ASCII or
351 * FTP_BINARY.
352 * @param int $startpos The position in the remote file to start uploading to.
353 * @throws FtpException
354 *
355 */
356 function ftp_put($ftp_stream, string $remote_file, string $local_file, int $mode = FTP_BINARY, int $startpos = 0): void
357 {
358 error_clear_last();
359 $result = \ftp_put($ftp_stream, $remote_file, $local_file, $mode, $startpos);
360 if ($result === false) {
361 throw FtpException::createFromPhpError();
362 }
363 }
364
365
366 /**
367 *
368 *
369 * @param resource $ftp_stream The link identifier of the FTP connection.
370 * @return string Returns the current directory name.
371 * @throws FtpException
372 *
373 */
374 function ftp_pwd($ftp_stream): string
375 {
376 error_clear_last();
377 $result = \ftp_pwd($ftp_stream);
378 if ($result === false) {
379 throw FtpException::createFromPhpError();
380 }
381 return $result;
382 }
383
384
385 /**
386 * ftp_rename renames a file or a directory on the FTP
387 * server.
388 *
389 * @param resource $ftp_stream The link identifier of the FTP connection.
390 * @param string $oldname The old file/directory name.
391 * @param string $newname The new name.
392 * @throws FtpException
393 *
394 */
395 function ftp_rename($ftp_stream, string $oldname, string $newname): void
396 {
397 error_clear_last();
398 $result = \ftp_rename($ftp_stream, $oldname, $newname);
399 if ($result === false) {
400 throw FtpException::createFromPhpError();
401 }
402 }
403
404
405 /**
406 * Removes the specified directory on the FTP server.
407 *
408 * @param resource $ftp_stream The link identifier of the FTP connection.
409 * @param string $directory The directory to delete. This must be either an absolute or relative
410 * path to an empty directory.
411 * @throws FtpException
412 *
413 */
414 function ftp_rmdir($ftp_stream, string $directory): void
415 {
416 error_clear_last();
417 $result = \ftp_rmdir($ftp_stream, $directory);
418 if ($result === false) {
419 throw FtpException::createFromPhpError();
420 }
421 }
422
423
424 /**
425 * ftp_site sends the given SITE
426 * command to the FTP server.
427 *
428 * SITE commands are not standardized, and vary from server
429 * to server. They are useful for handling such things as file permissions and
430 * group membership.
431 *
432 * @param resource $ftp_stream The link identifier of the FTP connection.
433 * @param string $command The SITE command. Note that this parameter isn't escaped so there may
434 * be some issues with filenames containing spaces and other characters.
435 * @throws FtpException
436 *
437 */
438 function ftp_site($ftp_stream, string $command): void
439 {
440 error_clear_last();
441 $result = \ftp_site($ftp_stream, $command);
442 if ($result === false) {
443 throw FtpException::createFromPhpError();
444 }
445 }
446
447
448 /**
449 * ftp_ssl_connect opens an explicit SSL-FTP connection to the
450 * specified host. That implies that
451 * ftp_ssl_connect will succeed even if the server is not
452 * configured for SSL-FTP, or its certificate is invalid. Only when
453 * ftp_login is called, the client will send the
454 * appropriate AUTH FTP command, so ftp_login will fail in
455 * the mentioned cases.
456 *
457 * @param string $host The FTP server address. This parameter shouldn't have any trailing
458 * slashes and shouldn't be prefixed with ftp://.
459 * @param int $port This parameter specifies an alternate port to connect to. If it is
460 * omitted or set to zero, then the default FTP port, 21, will be used.
461 * @param int $timeout This parameter specifies the timeout for all subsequent network operations.
462 * If omitted, the default value is 90 seconds. The timeout can be changed and
463 * queried at any time with ftp_set_option and
464 * ftp_get_option.
465 * @return resource Returns a SSL-FTP stream on success.
466 * @throws FtpException
467 *
468 */
469 function ftp_ssl_connect(string $host, int $port = 21, int $timeout = 90)
470 {
471 error_clear_last();
472 $result = \ftp_ssl_connect($host, $port, $timeout);
473 if ($result === false) {
474 throw FtpException::createFromPhpError();
475 }
476 return $result;
477 }
478
479
480 /**
481 * Returns the system type identifier of the remote FTP server.
482 *
483 * @param resource $ftp_stream The link identifier of the FTP connection.
484 * @return string Returns the remote system type.
485 * @throws FtpException
486 *
487 */
488 function ftp_systype($ftp_stream): string
489 {
490 error_clear_last();
491 $result = \ftp_systype($ftp_stream);
492 if ($result === false) {
493 throw FtpException::createFromPhpError();
494 }
495 return $result;
496 }
497