File: wait_for_ftp.php

package info (click to toggle)
php-league-flysystem 3.29.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,316 kB
  • sloc: php: 14,623; makefile: 48; sh: 31
file content (40 lines) | stat: -rw-r--r-- 954 bytes parent folder | download
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
<?php

use League\Flysystem\Ftp\FtpConnectionOptions;
use League\Flysystem\Ftp\FtpConnectionProvider;

include __DIR__ . '/../vendor/autoload.php';

$options = FtpConnectionOptions::fromArray([
   'host' => 'localhost',
   'port' => (int) ($argv[1] ?? 2122),
   'root' => '/',
   'username' => 'foo',
   'password' => 'pass',
]);

$provider = new FtpConnectionProvider();
$start = time();
$connected = false;

while (time() - $start < 60) {
    try {
        $provider->createConnection($options);
        $connected = true;
        break;
    } catch (Throwable $exception) {
        if (time() - $start < 30) {
            fwrite(STDOUT, "Exception while trying to connect:'\n");
            fwrite(STDOUT, (string) $exception);
            fwrite(STDOUT, "\n\n");
        }
        usleep(10000);
    }
}

if ( ! $connected) {
    fwrite(STDERR, "Unable to start FTP server.\n");
    exit(1);
}

fwrite(STDOUT, "Detected FTP server successfully.\n");