| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 | using Microsoft.VisualStudio.TestTools.UnitTesting;using Renci.SshNet.Common;using Renci.SshNet.Tests.Common;using Renci.SshNet.Tests.Properties;using System;using System.IO;namespace Renci.SshNet.Tests.Classes{    /// <summary>    /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.    /// </summary>    public partial class SftpClientTest : TestBase    {        [TestMethod]        [TestCategory("Sftp")]        [ExpectedException(typeof(SftpPermissionDeniedException))]        public void Test_Sftp_Download_Forbidden()        {            if (Resources.USERNAME == "root")                Assert.Fail("Must not run this test as root!");            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                string remoteFileName = "/root/.profile";                using (var ms = new MemoryStream())                {                    sftp.DownloadFile(remoteFileName, ms);                }                sftp.Disconnect();            }        }        [TestMethod]        [TestCategory("Sftp")]        [ExpectedException(typeof(SftpPathNotFoundException))]        public void Test_Sftp_Download_File_Not_Exists()        {            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                string remoteFileName = "/xxx/eee/yyy";                using (var ms = new MemoryStream())                {                    sftp.DownloadFile(remoteFileName, ms);                }                sftp.Disconnect();            }        }        [TestMethod]        [TestCategory("Sftp")]        [Description("Test passing null to BeginDownloadFile")]        [ExpectedException(typeof(ArgumentNullException))]        public void Test_Sftp_BeginDownloadFile_StreamIsNull()        {            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                sftp.BeginDownloadFile("aaaa", null, null, null);                sftp.Disconnect();            }        }        [TestMethod]        [TestCategory("Sftp")]        [Description("Test passing null to BeginDownloadFile")]        [ExpectedException(typeof(ArgumentException))]        public void Test_Sftp_BeginDownloadFile_FileNameIsWhiteSpace()        {            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                sftp.BeginDownloadFile("   ", new MemoryStream(), null, null);                sftp.Disconnect();            }        }        [TestMethod]        [TestCategory("Sftp")]        [Description("Test passing null to BeginDownloadFile")]        [ExpectedException(typeof(ArgumentException))]        public void Test_Sftp_BeginDownloadFile_FileNameIsNull()        {            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                sftp.BeginDownloadFile(null, new MemoryStream(), null, null);                sftp.Disconnect();            }        }        [TestMethod]        [TestCategory("Sftp")]        [ExpectedException(typeof(ArgumentException))]        public void Test_Sftp_EndDownloadFile_Invalid_Async_Handle()        {            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))            {                sftp.Connect();                var filename = Path.GetTempFileName();                this.CreateTestFile(filename, 1);                sftp.UploadFile(File.OpenRead(filename), "test123");                var async1 = sftp.BeginListDirectory("/", null, null);                var async2 = sftp.BeginDownloadFile("test123", new MemoryStream(), null, null);                sftp.EndDownloadFile(async1);            }        }    }}
 |