fix : change and fix SyncService
This commit is contained in:
@@ -182,7 +182,7 @@ function ftpSession($ctrl, string $user, string $pass, string $root): void
|
||||
case 'PASV':
|
||||
if (!$authed) { ftpSend($ctrl, '530 Not logged in'); break; }
|
||||
if ($pasvSock) fclose($pasvSock);
|
||||
$pasvPort = rand(49152, 65534);
|
||||
$pasvPort = rand(60000, 60020); // fixed range — must match firewall rule
|
||||
$pasvSock = @stream_socket_server("tcp://0.0.0.0:{$pasvPort}", $e1, $e2);
|
||||
if (!$pasvSock) { ftpSend($ctrl, '425 Cannot open passive connection'); break; }
|
||||
$localAddr = stream_socket_get_name($ctrl, false);
|
||||
@@ -220,15 +220,13 @@ function ftpSession($ctrl, string $user, string $pass, string $root): void
|
||||
$full = $root . $p;
|
||||
$dir = dirname($full);
|
||||
if (!is_dir($dir)) mkdir($dir, 0755, true);
|
||||
$fp = @fopen($full, 'wb');
|
||||
if (!$fp) { ftpSend($ctrl, '550 Cannot write file'); break; }
|
||||
$data = ftpOpenData($pasvSock);
|
||||
if (!$data) { ftpSend($ctrl, '425 No data connection'); break; }
|
||||
if (!$data) { fclose($fp); ftpSend($ctrl, '425 No data connection'); break; }
|
||||
ftpSend($ctrl, '150 Ready to receive');
|
||||
$fp = fopen($full, 'wb');
|
||||
if (!$fp) { fclose($data); ftpSend($ctrl, '550 Cannot write file'); break; }
|
||||
while (!feof($data)) {
|
||||
$buf = fread($data, 65536);
|
||||
if ($buf !== false && $buf !== '') fwrite($fp, $buf);
|
||||
}
|
||||
stream_set_timeout($data, 30);
|
||||
stream_copy_to_stream($data, $fp);
|
||||
fclose($fp);
|
||||
fclose($data);
|
||||
echo " STOR: {$p} (" . number_format(filesize($full)) . " bytes)\n";
|
||||
|
||||
Reference in New Issue
Block a user