Beispiel #1
0
        /*
         * Copes an FTP file to the local file system.
         */
        public virtual void FtpPickUp(string destinationFilePath, ConfigManager config, string fileName)
        {
            // Get the configuration
            var printXml = config.GetValue("printxml") == "true";

            // Connect the client.
            var sftpClient = this.FtpConnect(config);

            // Print the debug information.
            if (printXml)
            {
                Console.WriteLine("Picking up remote file outbound/" + fileName + ".asc");
                Console.WriteLine("Putting it at " + destinationFilePath);
            }

            try {
                // Download the file.
                var downloadStream = new FileStream(destinationFilePath, FileMode.Create, FileAccess.ReadWrite);
                sftpClient.DownloadFile(Path.Combine("outbound/", fileName + ".asc"), downloadStream);
                downloadStream.Close();
                if (printXml)
                {
                    Console.WriteLine("Removing remote file output/" + fileName + ".asc");
                }

                sftpClient.Delete("outbound/" + fileName + ".asc");
            }
            catch (SshConnectionException e) {
                throw new CnpOnlineException("Error occured while attempting to retrieve and save the file from SFTP",
                                             e);
            }
            catch (SftpPathNotFoundException e) {
                throw new CnpOnlineException("Error occured while attempting to locate desired SFTP file path", e);
            }
            finally {
                sftpClient.Disconnect();
            }
        }
Beispiel #2
0
        /*
         * Creates a web request to send.
         */
        public HttpWebRequest CreateWebRequest(string xmlRequest, ConfigManager config)
        {
            // Get the log file.
            string logFile = null;

            if (!string.IsNullOrEmpty(config.GetValue("logFile")))
            {
                logFile = config.GetValue("logFile");
            }

            // Get the rest of the configuration values.
            var neuterAccountNumbers  = "true".Equals(config.GetValue("neuterAccountNums"));
            var neuterUserCredentials = "true".Equals(config.GetValue("neuterUserCredentials"));
            var printXml = "true".Equals(config.GetValue("printxml"));

            // Get the request target information.
            var url = config.GetValue("url");

            ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
            var request = (HttpWebRequest)WebRequest.Create(url);

            // Output the request and log file.
            if (printXml)
            {
                Console.WriteLine(xmlRequest);
                Console.WriteLine(logFile);
            }

            // Log the request.
            if (logFile != null)
            {
                this.Log(xmlRequest, logFile, neuterAccountNumbers, neuterUserCredentials);
            }

            // Set up the request.
            request.ContentType = CONTENT_TYPE_TEXT_XML_UTF8;
            request.Method      = "POST";
            request.ServicePoint.MaxIdleTime       = 8000;
            request.ServicePoint.Expect100Continue = false;
            request.KeepAlive = true;
            if (!string.IsNullOrEmpty(config.GetValue("proxyHost")) && !string.IsNullOrEmpty(config.GetValue("proxyPort")))
            {
                var proxy = new WebProxy(config.GetValue("proxyHost"), int.Parse(config.GetValue("proxyPort")))
                {
                    BypassProxyOnLocal = true
                };
                request.Proxy = proxy;
            }

            // Set the timeout (only effective for non-async requests.
            try {
                request.Timeout = Convert.ToInt32(config.GetValue("timeout"));
            }
            catch (FormatException e) {
                request.Timeout = 60000;
            }

            // Invoke the event.
            this.OnHttpAction(Communications.RequestType.Request, xmlRequest, neuterAccountNumbers, neuterUserCredentials);

            // Return the request.
            return(request);
        }