fix : change and fix SyncService

This commit is contained in:
SajjadMahmoody
2026-04-18 00:53:44 +03:30
parent 7e8aa185ab
commit ea82f5968e
3 changed files with 38 additions and 26 deletions
+6 -8
View File
@@ -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";