summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/ftp.php
blob: 174882657cb03253aa3fcbb01918a470d45a5a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<?php

namespace Safe;

use Safe\Exceptions\FtpException;

/**
 * Sends an ALLO command to the remote FTP server to
 * allocate space for a file to be uploaded.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param int $filesize The number of bytes to allocate.
 * @param string $result A textual representation of the servers response will be returned by
 * reference in result if a variable is provided.
 * @throws FtpException
 *
 */
function ftp_alloc($ftp_stream, int $filesize, string &$result = null): void
{
    error_clear_last();
    $result = \ftp_alloc($ftp_stream, $filesize, $result);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 *
 *
 * @param resource $ftp
 * @param string $remote_file
 * @param string $local_file
 * @param int $mode
 * @throws FtpException
 *
 */
function ftp_append($ftp, string $remote_file, string $local_file, int $mode = FTP_BINARY): void
{
    error_clear_last();
    $result = \ftp_append($ftp, $remote_file, $local_file, $mode);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Changes to the parent directory.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @throws FtpException
 *
 */
function ftp_cdup($ftp_stream): void
{
    error_clear_last();
    $result = \ftp_cdup($ftp_stream);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Changes the current directory to the specified one.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $directory The target directory.
 * @throws FtpException
 *
 */
function ftp_chdir($ftp_stream, string $directory): void
{
    error_clear_last();
    $result = \ftp_chdir($ftp_stream, $directory);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Sets the permissions on the specified remote file to
 * mode.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param int $mode The new permissions, given as an octal value.
 * @param string $filename The remote file.
 * @return int Returns the new file permissions on success.
 * @throws FtpException
 *
 */
function ftp_chmod($ftp_stream, int $mode, string $filename): int
{
    error_clear_last();
    $result = \ftp_chmod($ftp_stream, $mode, $filename);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 * ftp_close closes the given link identifier
 * and releases the resource.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @throws FtpException
 *
 */
function ftp_close($ftp_stream): void
{
    error_clear_last();
    $result = \ftp_close($ftp_stream);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_connect opens an FTP connection to the
 * specified host.
 *
 * @param string $host The FTP server address. This parameter shouldn't have any trailing
 * slashes and shouldn't be prefixed with ftp://.
 * @param int $port This parameter specifies an alternate port to connect to. If it is
 * omitted or set to zero, then the default FTP port, 21, will be used.
 * @param int $timeout This parameter specifies the timeout in seconds for all subsequent network operations.
 * If omitted, the default value is 90 seconds. The timeout can be changed and
 * queried at any time with ftp_set_option and
 * ftp_get_option.
 * @return resource Returns a FTP stream on success.
 * @throws FtpException
 *
 */
function ftp_connect(string $host, int $port = 21, int $timeout = 90)
{
    error_clear_last();
    $result = \ftp_connect($host, $port, $timeout);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 * ftp_delete deletes the file specified by
 * path from the FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $path The file to delete.
 * @throws FtpException
 *
 */
function ftp_delete($ftp_stream, string $path): void
{
    error_clear_last();
    $result = \ftp_delete($ftp_stream, $path);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_fget retrieves remote_file
 * from the FTP server, and writes it to the given file pointer.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param resource $handle An open file pointer in which we store the data.
 * @param string $remote_file The remote file path.
 * @param int $mode The transfer mode. Must be either FTP_ASCII or
 * FTP_BINARY.
 * @param int $resumepos The position in the remote file to start downloading from.
 * @throws FtpException
 *
 */
function ftp_fget($ftp_stream, $handle, string $remote_file, int $mode = FTP_BINARY, int $resumepos = 0): void
{
    error_clear_last();
    $result = \ftp_fget($ftp_stream, $handle, $remote_file, $mode, $resumepos);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_fput uploads the data from a file pointer
 * to a remote file on the FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $remote_file The remote file path.
 * @param resource $handle An open file pointer on the local file. Reading stops at end of file.
 * @param int $mode The transfer mode. Must be either FTP_ASCII or
 * FTP_BINARY.
 * @param int $startpos The position in the remote file to start uploading to.
 * @throws FtpException
 *
 */
function ftp_fput($ftp_stream, string $remote_file, $handle, int $mode = FTP_BINARY, int $startpos = 0): void
{
    error_clear_last();
    $result = \ftp_fput($ftp_stream, $remote_file, $handle, $mode, $startpos);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_get retrieves a remote file from the FTP server,
 * and saves it into a local file.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $local_file The local file path (will be overwritten if the file already exists).
 * @param string $remote_file The remote file path.
 * @param int $mode The transfer mode. Must be either FTP_ASCII or
 * FTP_BINARY.
 * @param int $resumepos The position in the remote file to start downloading from.
 * @throws FtpException
 *
 */
function ftp_get($ftp_stream, string $local_file, string $remote_file, int $mode = FTP_BINARY, int $resumepos = 0): void
{
    error_clear_last();
    $result = \ftp_get($ftp_stream, $local_file, $remote_file, $mode, $resumepos);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Logs in to the given FTP stream.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $username The username (USER).
 * @param string $password The password (PASS).
 * @throws FtpException
 *
 */
function ftp_login($ftp_stream, string $username, string $password): void
{
    error_clear_last();
    $result = \ftp_login($ftp_stream, $username, $password);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Creates the specified directory on the FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $directory The name of the directory that will be created.
 * @return string Returns the newly created directory name on success.
 * @throws FtpException
 *
 */
function ftp_mkdir($ftp_stream, string $directory): string
{
    error_clear_last();
    $result = \ftp_mkdir($ftp_stream, $directory);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 *
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $directory The directory to be listed.
 * @return array Returns an array of arrays with file infos from the specified directory on success.
 * @throws FtpException
 *
 */
function ftp_mlsd($ftp_stream, string $directory): array
{
    error_clear_last();
    $result = \ftp_mlsd($ftp_stream, $directory);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 *
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $directory The directory to be listed. This parameter can also include arguments, eg.
 * ftp_nlist($conn_id, "-la /your/dir");
 * Note that this parameter isn't escaped so there may be some issues with
 * filenames containing spaces and other characters.
 * @return array Returns an array of filenames from the specified directory on success.
 * @throws FtpException
 *
 */
function ftp_nlist($ftp_stream, string $directory): array
{
    error_clear_last();
    $result = \ftp_nlist($ftp_stream, $directory);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 * ftp_pasv turns on or off passive mode. In
 * passive mode, data connections are initiated by the client,
 * rather than by the server.
 * It may be needed if the client is behind firewall.
 *
 * Please note that ftp_pasv can only be called after a
 * successful login or otherwise it will fail.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param bool $pasv If TRUE, the passive mode is turned on, else it's turned off.
 * @throws FtpException
 *
 */
function ftp_pasv($ftp_stream, bool $pasv): void
{
    error_clear_last();
    $result = \ftp_pasv($ftp_stream, $pasv);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_put stores a local file on the FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $remote_file The remote file path.
 * @param string $local_file The local file path.
 * @param int $mode The transfer mode. Must be either FTP_ASCII or
 * FTP_BINARY.
 * @param int $startpos The position in the remote file to start uploading to.
 * @throws FtpException
 *
 */
function ftp_put($ftp_stream, string $remote_file, string $local_file, int $mode = FTP_BINARY, int $startpos = 0): void
{
    error_clear_last();
    $result = \ftp_put($ftp_stream, $remote_file, $local_file, $mode, $startpos);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 *
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @return string Returns the current directory name.
 * @throws FtpException
 *
 */
function ftp_pwd($ftp_stream): string
{
    error_clear_last();
    $result = \ftp_pwd($ftp_stream);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 * ftp_rename renames a file or a directory on the FTP
 * server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $oldname The old file/directory name.
 * @param string $newname The new name.
 * @throws FtpException
 *
 */
function ftp_rename($ftp_stream, string $oldname, string $newname): void
{
    error_clear_last();
    $result = \ftp_rename($ftp_stream, $oldname, $newname);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * Removes the specified directory on the FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $directory The directory to delete. This must be either an absolute or relative
 * path to an empty directory.
 * @throws FtpException
 *
 */
function ftp_rmdir($ftp_stream, string $directory): void
{
    error_clear_last();
    $result = \ftp_rmdir($ftp_stream, $directory);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_site sends the given SITE
 * command to the FTP server.
 *
 * SITE commands are not standardized, and vary from server
 * to server. They are useful for handling such things as file permissions and
 * group membership.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @param string $command The SITE command. Note that this parameter isn't escaped so there may
 * be some issues with filenames containing spaces and other characters.
 * @throws FtpException
 *
 */
function ftp_site($ftp_stream, string $command): void
{
    error_clear_last();
    $result = \ftp_site($ftp_stream, $command);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
}


/**
 * ftp_ssl_connect opens an explicit SSL-FTP connection to the
 * specified host. That implies that
 * ftp_ssl_connect will succeed even if the server is not
 * configured for SSL-FTP, or its certificate is invalid. Only when
 * ftp_login is called, the client will send the
 * appropriate AUTH FTP command, so ftp_login will fail in
 * the mentioned cases.
 *
 * @param string $host The FTP server address. This parameter shouldn't have any trailing
 * slashes and shouldn't be prefixed with ftp://.
 * @param int $port This parameter specifies an alternate port to connect to. If it is
 * omitted or set to zero, then the default FTP port, 21, will be used.
 * @param int $timeout This parameter specifies the timeout for all subsequent network operations.
 * If omitted, the default value is 90 seconds. The timeout can be changed and
 * queried at any time with ftp_set_option and
 * ftp_get_option.
 * @return resource Returns a SSL-FTP stream on success.
 * @throws FtpException
 *
 */
function ftp_ssl_connect(string $host, int $port = 21, int $timeout = 90)
{
    error_clear_last();
    $result = \ftp_ssl_connect($host, $port, $timeout);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}


/**
 * Returns the system type identifier of the remote FTP server.
 *
 * @param resource $ftp_stream The link identifier of the FTP connection.
 * @return string Returns the remote system type.
 * @throws FtpException
 *
 */
function ftp_systype($ftp_stream): string
{
    error_clear_last();
    $result = \ftp_systype($ftp_stream);
    if ($result === false) {
        throw FtpException::createFromPhpError();
    }
    return $result;
}