Click or drag to resize

OutputFileServerDeviceProcessingScriptTemplate Field

Default processing script template

Namespace: Seal.Model
Assembly: SealLibrary (in SealLibrary.dll) Version: 10.0.1.0+a44cd3a7f03c2bf3cdbd971a878c679e40bed08a
Syntax
C#
public const string ProcessingScriptTemplate = "@using Renci.SshNet\n@using FluentFTP\n@using System.IO\n@using System.Security.Authentication\n@{\n    //Upload the file to the server\n    Report report = Model;\n    ReportOutput output = report.OutputToExecute;\n    var device = output.Device as OutputFileServerDevice;\n\n    var resultFileName = (output.ZipResult ? Path.GetFileNameWithoutExtension(report.ResultFileName) + ".zip" : Path.GetFileNameWithoutExtension(report.ResultFileName) + Path.GetExtension(report.ResultFilePath));\n    device.HandleZipOptions(report);\n\n    //Put file\n    var remotePath = output.FileServerFolderWithSeparators + resultFileName;\n\n    if (device.Protocol == FileServerProtocol.FTP)\n    {\n        //Refer to https://github.com/robinrodricks/FluentFTP\n        using (var client = new FtpClient()) {\n            client.Host = device.HostName;\n            client.Credentials.UserName = device.UserName;\n            client.Credentials.Password = device.ClearPassword;\n\n            client.Config.EncryptionMode = FtpEncryptionMode.Auto;\n            client.Config.ValidateAnyCertificate = true;\n            if (device.PortNumber == 0) {\n                client.AutoConnect();\n            }\n            else {\n                client.Port = device.PortNumber;\n                //SSL Configuration can be defined here\n                /*\n                client.Config.EncryptionMode = FtpEncryptionMode.Explicit;\n                client.Config.SslProtocols = SslProtocols.Tls12;\n                client.ValidateCertificate += new FtpSslValidation(delegate (FluentFTP.Client.BaseClient.BaseFtpClient control, FtpSslValidationEventArgs e)\n                {\n                    if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None) {\n                        e.Accept = false;\n                    }\n                    else {\n                        e.Accept = true;\n                    }\n                });\n                */\n                client.Connect();\n            }\n            client.UploadFile(report.ResultFilePath, remotePath);\n            client.Disconnect();\n        }\n    }\n    else if (device.Protocol == FileServerProtocol.SFTP)\n    {\n        //Refer to https://github.com/sshnet/SSH.NET\n        using (var sftp = new SftpClient(device.HostName, device.PortNumber, device.UserName, device.ClearPassword))\n        {\n            sftp.Connect();\n            using (Stream fileStream = File.Create(report.ResultFilePath))\n            {\n                sftp.UploadFile(fileStream, remotePath);\n            }\n            sftp.Disconnect();\n        }\n    }\n    else if (device.Protocol == FileServerProtocol.SCP)\n    {\n        //Refer to https://github.com/sshnet/SSH.NET\n        using (var scp = new ScpClient(device.HostName, device.PortNumber, device.UserName, device.ClearPassword))\n        {\n            scp.Connect();\n            using (Stream fileStream = File.Create(report.ResultFilePath))\n            {\n                scp.Upload(fileStream, remotePath);\n            }\n            scp.Disconnect();\n        }\n    }\n\n    output.Information = report.Translate("Report result generated in '{0}'", remotePath);\n    report.LogMessage("Report result generated in '{0}'", remotePath);\n}\n"

Field Value

String
See Also