#494 backup ftp server
This commit is contained in:
parent
01dbdd539c
commit
1405b5373a
@ -277,6 +277,28 @@ namespace RMuseum.Services.Implementation
|
||||
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;
|
||||
|
||||
foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" })
|
||||
{
|
||||
var localFilePath = GetImagePath(rPictureFile, imageSizeString).Result;
|
||||
var remoteFilePath = $"{Configuration.GetSection("BackupFTPServer")["RootPath"]}/images/{rPictureFile.FolderName}/{imageSizeString}/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
|
||||
}
|
||||
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -359,6 +381,30 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" })
|
||||
{
|
||||
var localFilePath = GetImagePath(rPictureFile, imageSizeString).Result;
|
||||
var remoteFilePath = $"{Configuration.GetSection("BackupFTPServer")["RootPath"]}/images/{rPictureFile.FolderName}/{imageSizeString}/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
|
||||
}
|
||||
|
||||
await ftpClient.Disconnect();
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -672,6 +718,25 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
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;
|
||||
|
||||
var localFilePath = _simpleImageStorage.GetImagePath(image).Result;
|
||||
var remoteFilePath = $"{Configuration.GetSection("BackupFTPServer")["RootPath"]}/images/CroppedImages/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
|
||||
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
return new RServiceResult<RImage>(image);
|
||||
}
|
||||
return res;
|
||||
|
||||
@ -268,7 +268,31 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
|
||||
|
||||
if (model.Published && 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;
|
||||
foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" })
|
||||
{
|
||||
var localFilePath = _pictureFileService.GetImagePath(dbModel.Picture, imageSizeString).Result;
|
||||
if (imageSizeString == "norm")
|
||||
{
|
||||
dbModel.Picture.ExternalNormalSizeImageUrl = $"{Configuration.GetSection("BackupFTPServer")["RootUrl"]}/PoetsPhotoSuggestions/{imageSizeString}/{Path.GetFileName(localFilePath)}";
|
||||
}
|
||||
var remoteFilePath = $"{Configuration.GetSection("BackupFTPServer")["RootPath"]}/images/PoetsPhotoSuggestions/{imageSizeString}/{Path.GetFileName(localFilePath)}";
|
||||
await ftpClient.UploadFile(localFilePath, remoteFilePath);
|
||||
}
|
||||
await ftpClient.Disconnect();
|
||||
}
|
||||
|
||||
bool publishIsChanged = model.Published != dbModel.Published;
|
||||
if(publishIsChanged)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user