diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-CatUtils.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-CatUtils.cs index 765705c9..f4cb8ad5 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-CatUtils.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-CatUtils.cs @@ -336,6 +336,27 @@ namespace RMuseum.Services.Implementation await ftpClient.UploadFile(localFilePath, remoteFilePath); await ftpClient.Disconnect(); } + + if (bool.Parse(Configuration.GetSection("BackupFTPServer")["UploadEnabled"])) + { + var ftpClient = new AsyncFtpClient + ( + Configuration.GetSection("BackupFTPServer")["Host"], + Configuration.GetSection("BackupFTPServer")["Username"], + Configuration.GetSection("BackupFTPServer")["Password"] + ); + ftpClient.ValidateCertificate += FtpClient_ValidateCertificate; + await ftpClient.AutoConnect(); + ftpClient.Config.RetryAttempts = 3; + RServiceResult imgPath = _imageFileService.GetImagePath(img.Result); + if (!string.IsNullOrEmpty(imgPath.ExceptionString)) + return new RServiceResult(null, imgPath.ExceptionString); + + var localFilePath = imgPath.Result; + var remoteFilePath = $"{Configuration.GetSection("BackupFTPServer")["RootPath"]}/images/CategoryImages/{Path.GetFileName(localFilePath)}"; + await ftpClient.UploadFile(localFilePath, remoteFilePath); + await ftpClient.Disconnect(); + } } cat.BookName = bookName; cat.RImageId = imageId;