protected virtual void SendFTPFiles(Attachment[] emailAttachments, bool useSFTP,
string ftpUrl, int port, string username, string password, string folder, string sftpEncryption)
{
using (SftpClient client = new SftpClient(ftpUrl, port, username, password))
{
KeyValuePair<string, CipherInfo> temp = client.ConnectionInfo.Encryptions.FirstOrDefault(e => e.Key == sftpEncryption);
if (temp.Key == sftpEncryption)
{
client.ConnectionInfo.Encryptions.Clear();
client.ConnectionInfo.Encryptions.Add(temp);
}
client.Connect();
if (!string.IsNullOrWhiteSpace(folder)) client.ChangeDirectory(folder);
foreach (Attachment a in emailAttachments)
{
using (MemoryStream stream = new MemoryStream())
{
a.ContentStream.Seek(0, SeekOrigin.Begin);
a.ContentStream.CopyTo(stream);
a.ContentStream.Seek(0, SeekOrigin.Begin);
stream.Seek(0, SeekOrigin.Begin);
client.BufferSize = 4 * 1024;
client.UploadFile(stream, a.Name);
//TODO : ??
}
}
}
}
↧
New Post: How can i get response staus and description when i use SftpClient.UploadFile()?
↧