Litle.Sdk.Communications.FtpPickUp C# (CSharp) Method

FtpPickUp() public method

public FtpPickUp ( string destinationFilePath, string>.Dictionary config, string fileName ) : void
destinationFilePath string
config string>.Dictionary
fileName string
return void
        public virtual void FtpPickUp(string destinationFilePath, Dictionary<string, string> config, string fileName)
        {
            ChannelSftp channelSftp;

            var printxml = config["printxml"] == "true";

            var url = config["sftpUrl"];
            var username = config["sftpUsername"];
            var password = config["sftpPassword"];
            var knownHostsFile = config["knownHostsFile"];

            var jsch = new JSch();
            jsch.setKnownHosts(knownHostsFile);

            var session = jsch.getSession(username, url);
            session.setPassword(password);

            try
            {
                session.connect();

                var channel = session.openChannel("sftp");
                channel.connect();
                channelSftp = (ChannelSftp)channel;
            }
            catch (SftpException e)
            {
                throw new LitleOnlineException("Error occured while attempting to establish an SFTP connection", e);
            }

            try
            {
                if (printxml)
                {
                    Console.WriteLine("Picking up remote file outbound/" + fileName + ".asc");
                    Console.WriteLine("Putting it at " + destinationFilePath);
                }
                channelSftp.get("outbound/" + fileName + ".asc", destinationFilePath);
                if (printxml)
                {
                    Console.WriteLine("Removing remote file output/" + fileName + ".asc");
                }
                channelSftp.rm("outbound/" + fileName + ".asc");
            }
            catch (SftpException e)
            {
                throw new LitleOnlineException("Error occured while attempting to retrieve and save the file from SFTP", e);
            }

            channelSftp.quit();

            session.disconnect();
        }

Usage Example

コード例 #1
0
        public litleResponse receiveFromLitle(string batchFileName)
        {
            communication.FtpPickUp(responseDirectory + batchFileName, config, batchFileName);

            var stringBuilder = _cache[responseDirectory + batchFileName];
            var litleResponse = litleXmlSerializer.DeserializeObjectFromString(stringBuilder.ToString());

            return(litleResponse);
        }
All Usage Examples Of Litle.Sdk.Communications::FtpPickUp