bug fix in ftp upload server
This commit is contained in:
parent
752295b83a
commit
5fc8fa9d67
|
@ -91,7 +91,7 @@ final class DatabaseController extends AbstractController
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'result' => 1,
|
'result' => 1,
|
||||||
'filename' => $filepath,
|
'filename' => $filename,
|
||||||
'message' => 'پشتیبان با موفقیت ایجاد شد'
|
'message' => 'پشتیبان با موفقیت ایجاد شد'
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -165,12 +165,16 @@ final class DatabaseController extends AbstractController
|
||||||
$remoteDir = dirname($remotePath);
|
$remoteDir = dirname($remotePath);
|
||||||
|
|
||||||
// بررسی دسترسی نوشتن در مسیر
|
// بررسی دسترسی نوشتن در مسیر
|
||||||
$testFile = 'test_' . time() . '.txt';
|
$testFileLocal = tempnam(sys_get_temp_dir(), 'ftp_test_');
|
||||||
if (!@ftp_put($ftp, $testFile, 'test', FTP_ASCII)) {
|
file_put_contents($testFileLocal, 'test');
|
||||||
|
$testFileRemote = 'test_' . time() . '.txt';
|
||||||
|
if (!@ftp_put($ftp, $testFileRemote, $testFileLocal, FTP_ASCII)) {
|
||||||
|
unlink($testFileLocal);
|
||||||
ftp_close($ftp);
|
ftp_close($ftp);
|
||||||
throw new \Exception('کاربر FTP دسترسی نوشتن ندارد');
|
throw new \Exception('کاربر FTP دسترسی نوشتن ندارد');
|
||||||
}
|
}
|
||||||
ftp_delete($ftp, $testFile);
|
ftp_delete($ftp, $testFileRemote);
|
||||||
|
unlink($testFileLocal);
|
||||||
|
|
||||||
// ایجاد مسیر در صورت عدم وجود
|
// ایجاد مسیر در صورت عدم وجود
|
||||||
$this->createFtpDirectory($ftp, $remoteDir);
|
$this->createFtpDirectory($ftp, $remoteDir);
|
||||||
|
@ -181,8 +185,13 @@ final class DatabaseController extends AbstractController
|
||||||
throw new \Exception("خطا در تغییر به مسیر {$remoteDir} در سرور FTP");
|
throw new \Exception("خطا در تغییر به مسیر {$remoteDir} در سرور FTP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// قبل از آپلود فایل
|
||||||
|
echo("در حال آپلود به: $remoteDir / $remotePath");
|
||||||
|
|
||||||
// آپلود فایل
|
// آپلود فایل
|
||||||
if (!ftp_put($ftp, basename($remotePath), $filepath, FTP_BINARY)) {
|
$result = ftp_put($ftp, basename($remotePath), $filepath, FTP_BINARY);
|
||||||
|
echo("نتیجه آپلود: " . ($result ? 'موفق' : 'ناموفق'));
|
||||||
|
if (!$result) {
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
ftp_close($ftp);
|
ftp_close($ftp);
|
||||||
throw new \Exception('خطا در آپلود فایل به سرور FTP: ' . ($error['message'] ?? 'خطای نامشخص'));
|
throw new \Exception('خطا در آپلود فایل به سرور FTP: ' . ($error['message'] ?? 'خطای نامشخص'));
|
||||||
|
|
|
@ -155,11 +155,13 @@ final class RegistrySettingsController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
// تست دسترسی به مسیر
|
// تست دسترسی به مسیر
|
||||||
if (!ftp_chdir($ftp, $data['path'])) {
|
if (!@ftp_chdir($ftp, $data['path'])) {
|
||||||
|
$currentDir = ftp_pwd($ftp); // دریافت مسیر فعلی
|
||||||
ftp_close($ftp);
|
ftp_close($ftp);
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'مسیر مورد نظر قابل دسترسی نیست'
|
'message' => 'مسیر مورد نظر قابل دسترسی نیست',
|
||||||
|
'suggested_path' => $currentDir // پیشنهاد مسیر فعلی
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue