Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: How can i get response staus and description when i use SftpClient.UploadFile()?

$
0
0
 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 : ??
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>