private async Task UploadFile(JobInitResult jobInitResult, FileInfo toBeConverted) { Licensing.Key = sftpLicenseKey; using (var client = new Sftp()) { await client.ConnectAsync(jobInitResult.UploadUrl, jobInitResult.Port); await client.LoginAsync(jobInitResult.User, jobInitResult.Password); var uploadName = $"{client.GetCurrentDirectory()}{toBeConverted.Name}"; Log.Verbose("Uploading file {FullName} to {UploadName}", toBeConverted.FullName, uploadName); if (toBeConverted.Exists) { await client.PutFileAsync(toBeConverted.FullName, uploadName); Log.Verbose("Upload successfull"); } else { Log.Verbose("File {FullName} does not exist, or cannot be accessed.", toBeConverted.FullName); throw new FileNotFoundException("File could not be uploaded, because source file is not accessible or cannot be found", toBeConverted.FullName); } } }
public Task Consume(ConsumeContext <JobInitRequest> context) { using (LogContext.PushProperty(nameof(context.ConversationId), context.ConversationId)) { Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(JobInitRequest), context.ConversationId); // Verify if file type is supported var supportedFileTypes = manager.GetSupportedFileTypes(context.Message.RequestedProcessType); var fileToConvert = new FileInfo(context.Message.FileNameWithExtension); if (supportedFileTypes.Contains(fileToConvert.Extension.Substring(1).ToLower())) { var jobInitResult = sftpServer.RegisterNewJob(context.Message); return(context.RespondAsync(jobInitResult)); } var errorResult = new JobInitResult { IsInvalid = true, ErrorMessage = $"Extension {fileToConvert.Extension} is not supported. Supported Extensions are {string.Join(", ", supportedFileTypes)}" }; return(context.RespondAsync(errorResult)); } }
private void UploadFile(JobInitResult jobResult, FileInfo toBeConverted) { Licensing.Key = DocumentConverterSettings.Default.SftpLicenseKey; using (var client = new Sftp()) { client.Connect(jobResult.UploadUrl, jobResult.Port); client.Login(jobResult.User, jobResult.Password); client.PutFile(toBeConverted.FullName, $"{client.GetCurrentDirectory()}{toBeConverted.Name}"); } }
private async Task UploadFile(JobInitResult jobInitResult, FileInfo toBeConverted) { Licensing.Key = sftpLicenseKey; using (var client = new Sftp()) { await client.ConnectAsync(jobInitResult.UploadUrl, jobInitResult.Port); await client.LoginAsync(jobInitResult.User, jobInitResult.Password); await client.PutFileAsync(toBeConverted.FullName, $"{client.GetCurrentDirectory()}{toBeConverted.Name}"); } }
public JobInitResult RegisterNewJob(JobInitRequest jobInitRequest) { if (fileServer == null) { throw new InvalidOperationException("Sftp server is not configured and started"); } try { // Create a new unique user and a unique directory for that user var newJobGuid = Guid.NewGuid().ToString("N"); var user = new FileServerUser(newJobGuid, password); Debug.Assert(user != null); var di = GetJobDirectory(newJobGuid); di.Create(); // Create a sftp file system object and assign it to the user. var localFileSystem = CreateFileSystem(di.FullName); user.SetFileSystem(localFileSystem); lock (fileServerLock) { fileServer.Users.Add(user); } var jobInitResult = new JobInitResult { JobGuid = newJobGuid, User = user.Name, Password = password, UploadUrl = baseAddress, Port = port }; // Add the information about the job to our local in memory storage var jobInfoDetails = new JobInfoDetails { Request = jobInitRequest, Result = jobInitResult }; jobStorage.AddOrUpdate(newJobGuid, jobInfoDetails, (k, v) => v); return(jobInitResult); } catch (Exception e) { Log.Error(e, e.Message); return(new JobInitResult { IsInvalid = true, ErrorMessage = e.Message }); } }