当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.CreateText方法代码示例

本文整理汇总了C#中Renci.SshNet.SftpClient.CreateText方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.CreateText方法的具体用法?C# SftpClient.CreateText怎么用?C# SftpClient.CreateText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SftpClient的用法示例。


在下文中一共展示了SftpClient.CreateText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send

        public override void Send(string overrideValue)
        {
            overrideValue = overrideValue.Replace("\r", "").Replace("\n", "");

            try
            {
                int port = 22;
                var hostname = Settings.SFTPHostname;
                if (hostname.StartsWith("sftp://")) {
                    hostname = hostname.Replace("sftp://", "");
                }
                if (hostname.Contains(":")) {
                    var parts = hostname.Split(':');
                    hostname = parts[0];
                    port = int.Parse(parts[1]);
                }

                ConnectionInfo conn = new ConnectionInfo(hostname, port, Settings.SFTPUsername, new AuthenticationMethod[1] {
                    new PasswordAuthenticationMethod(Settings.SFTPUsername, Settings.SFTPPassword)
                });

                using (var client = new SftpClient(conn))
                {
                    client.Connect();

                    var file = client.CreateText(currentDespatch.SalesOrderNumber + ".csv");
                    try {
                        file.WriteLine(overrideValue);
                    }
                    finally {
                        file.Close();
                    }

                    var path = Path.Combine(Path.GetDirectoryName(Settings.LabelDirectory), "MHI.csv");
                    File.AppendAllText(path, string.Format("\"{0}\",{1}\n", DateTime.Now.ToLongTimeString(), overrideValue));

                    client.Disconnect();
                }
                WriteLog(string.Format("Sent request to {0} tracking number {1} service type {2}...", PluginName, Settings.MHIPrefix + currentDespatch.SalesOrderNumber, currentDespatch.ServiceTypeName), Color.Black);

                var ps = new PrinterSettings { PrinterName = Settings.PrinterName };
                var maxResolution = ps.PrinterResolutions.OfType<PrinterResolution>()
                                                         .OrderByDescending(r => r.X)
                                                         .ThenByDescending(r => r.Y)
                                                         .First();

                PrintDocument pd = new PrintDocument();
                pd.PrinterSettings.PrinterName = Settings.PrinterName;
                pd.PrintController = new StandardPrintController();
                pd.DefaultPageSettings.Margins = pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
                pd.DefaultPageSettings.Landscape = true;
                pd.OriginAtMargins = true;

                Image label = generateLabel(maxResolution.X, maxResolution.Y);

                label.Save(Path.Combine(Settings.LabelDirectory, currentDespatch.SalesOrderNumber + "-" + currentDespatch.DespatchNumber + ".png"), ImageFormat.Png);

                pd.PrintPage += (sndr, args) =>
                {
                    args.Graphics.DrawImage(label, args.MarginBounds);
                };
                pd.Print();

                WriteLog(string.Format("Print request sent to {0}...", Settings.PrinterName), Color.Black);

                label.Dispose();

                if (this.NeedsCN22(currentDespatch.ShippingAddressCountry)) {
                    PrintDocument pd22 = new PrintDocument();
                    pd22.PrinterSettings.PrinterName = Settings.PrinterName;
                    pd22.PrintController = new StandardPrintController();
                    pd22.DefaultPageSettings.Margins = pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
                    pd22.DefaultPageSettings.Landscape = false;
                    pd22.OriginAtMargins = true;

                    var cn22label = this.GenerateCN22(currentDespatch.SalesOrderNumber, currentDespatch.Items);

                    pd22.PrintPage += (sndr, args) =>
                    {
                        args.Graphics.DrawImage(cn22label, args.MarginBounds);
                    };
                    pd22.Print();

                    cn22label.Dispose();
                }

                trackingNumber = Settings.MHIPrefix + currentDespatch.SalesOrderNumber;
                Result = Settings.MHIPrefix + currentDespatch.SalesOrderNumber;
            }
            catch (Exception e)
            {
                WriteLog(string.Format("Exception on SEND:\n{0}", e.ToString()), Color.Red);
            }
        }
开发者ID:AudriusButkevicius,项目名称:probable-bassoon,代码行数:94,代码来源:MHIPlugin.cs


注:本文中的Renci.SshNet.SftpClient.CreateText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。