本文整理汇总了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);
}
}