|
| 1 | +using System.Diagnostics; |
| 2 | + |
| 3 | +using Renci.SshNet.Common; |
| 4 | + |
| 5 | +namespace Renci.SshNet.IntegrationTests.OldIntegrationTests |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. |
| 9 | + /// </summary> |
| 10 | + public partial class SftpClientTest : IntegrationTestBase |
| 11 | + { |
| 12 | + [TestMethod] |
| 13 | + [TestCategory("Sftp")] |
| 14 | + [ExpectedException(typeof(SshConnectionException))] |
| 15 | + public void Test_Sftp_EnumerateDirectory_Without_Connecting() |
| 16 | + { |
| 17 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 18 | + { |
| 19 | + var files = sftp.EnumerateDirectory("."); |
| 20 | + foreach (var file in files) |
| 21 | + { |
| 22 | + Debug.WriteLine(file.FullName); |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + [TestMethod] |
| 28 | + [TestCategory("Sftp")] |
| 29 | + [TestCategory("integration")] |
| 30 | + [ExpectedException(typeof(SftpPermissionDeniedException))] |
| 31 | + public void Test_Sftp_EnumerateDirectory_Permission_Denied() |
| 32 | + { |
| 33 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 34 | + { |
| 35 | + sftp.Connect(); |
| 36 | + |
| 37 | + var files = sftp.EnumerateDirectory("/root"); |
| 38 | + foreach (var file in files) |
| 39 | + { |
| 40 | + Debug.WriteLine(file.FullName); |
| 41 | + } |
| 42 | + |
| 43 | + sftp.Disconnect(); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + [TestMethod] |
| 48 | + [TestCategory("Sftp")] |
| 49 | + [TestCategory("integration")] |
| 50 | + [ExpectedException(typeof(SftpPathNotFoundException))] |
| 51 | + public void Test_Sftp_EnumerateDirectory_Not_Exists() |
| 52 | + { |
| 53 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 54 | + { |
| 55 | + sftp.Connect(); |
| 56 | + |
| 57 | + var files = sftp.EnumerateDirectory("/asdfgh"); |
| 58 | + foreach (var file in files) |
| 59 | + { |
| 60 | + Debug.WriteLine(file.FullName); |
| 61 | + } |
| 62 | + |
| 63 | + sftp.Disconnect(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + [TestMethod] |
| 68 | + [TestCategory("Sftp")] |
| 69 | + [TestCategory("integration")] |
| 70 | + public void Test_Sftp_EnumerateDirectory_Current() |
| 71 | + { |
| 72 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 73 | + { |
| 74 | + sftp.Connect(); |
| 75 | + |
| 76 | + var files = sftp.EnumerateDirectory("."); |
| 77 | + |
| 78 | + Assert.IsTrue(files.Count() > 0); |
| 79 | + |
| 80 | + foreach (var file in files) |
| 81 | + { |
| 82 | + Debug.WriteLine(file.FullName); |
| 83 | + } |
| 84 | + |
| 85 | + sftp.Disconnect(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + [TestMethod] |
| 90 | + [TestCategory("Sftp")] |
| 91 | + [TestCategory("integration")] |
| 92 | + public void Test_Sftp_EnumerateDirectory_Empty() |
| 93 | + { |
| 94 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 95 | + { |
| 96 | + sftp.Connect(); |
| 97 | + |
| 98 | + var files = sftp.EnumerateDirectory(string.Empty); |
| 99 | + |
| 100 | + Assert.IsTrue(files.Count() > 0); |
| 101 | + |
| 102 | + foreach (var file in files) |
| 103 | + { |
| 104 | + Debug.WriteLine(file.FullName); |
| 105 | + } |
| 106 | + |
| 107 | + sftp.Disconnect(); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + [TestMethod] |
| 112 | + [TestCategory("Sftp")] |
| 113 | + [TestCategory("integration")] |
| 114 | + [Description("Test passing null to EnumerateDirectory.")] |
| 115 | + [ExpectedException(typeof(ArgumentNullException))] |
| 116 | + public void Test_Sftp_EnumerateDirectory_Null() |
| 117 | + { |
| 118 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 119 | + { |
| 120 | + sftp.Connect(); |
| 121 | + |
| 122 | + var files = sftp.EnumerateDirectory(null); |
| 123 | + |
| 124 | + Assert.IsTrue(files.Count() > 0); |
| 125 | + |
| 126 | + foreach (var file in files) |
| 127 | + { |
| 128 | + Debug.WriteLine(file.FullName); |
| 129 | + } |
| 130 | + |
| 131 | + sftp.Disconnect(); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + [TestMethod] |
| 136 | + [TestCategory("Sftp")] |
| 137 | + [TestCategory("integration")] |
| 138 | + public void Test_Sftp_EnumerateDirectory_HugeDirectory() |
| 139 | + { |
| 140 | + var stopwatch = Stopwatch.StartNew(); |
| 141 | + try |
| 142 | + { |
| 143 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 144 | + { |
| 145 | + sftp.Connect(); |
| 146 | + sftp.ChangeDirectory("/home/" + User.UserName); |
| 147 | + |
| 148 | + var count = 10000; |
| 149 | + // Create 10000 directory items |
| 150 | + for (int i = 0; i < count; i++) |
| 151 | + { |
| 152 | + sftp.CreateDirectory(string.Format("test_{0}", i)); |
| 153 | + } |
| 154 | + Debug.WriteLine(string.Format("Created {0} directories within {1} seconds", count, stopwatch.Elapsed.TotalSeconds)); |
| 155 | + |
| 156 | + stopwatch.Reset(); |
| 157 | + stopwatch.Start(); |
| 158 | + var files = sftp.EnumerateDirectory("."); |
| 159 | + Debug.WriteLine(string.Format("Listed {0} directories within {1} seconds", count, stopwatch.Elapsed.TotalSeconds)); |
| 160 | + |
| 161 | + // Ensure that directory has at least 10000 items |
| 162 | + stopwatch.Reset(); |
| 163 | + stopwatch.Start(); |
| 164 | + var actualCount = files.Count(); |
| 165 | + Assert.IsTrue(actualCount >= count); |
| 166 | + Debug.WriteLine(string.Format("Used {0} items within {1} seconds", actualCount, stopwatch.Elapsed.TotalSeconds)); |
| 167 | + |
| 168 | + sftp.Disconnect(); |
| 169 | + } |
| 170 | + } |
| 171 | + finally |
| 172 | + { |
| 173 | + stopwatch.Reset(); |
| 174 | + stopwatch.Start(); |
| 175 | + RemoveAllFiles(); |
| 176 | + stopwatch.Stop(); |
| 177 | + Debug.WriteLine(string.Format("Removed all files within {0} seconds", stopwatch.Elapsed.TotalSeconds)); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + [TestMethod] |
| 182 | + [TestCategory("Sftp")] |
| 183 | + [TestCategory("integration")] |
| 184 | + [ExpectedException(typeof(SshConnectionException))] |
| 185 | + public void Test_Sftp_EnumerateDirectory_After_Disconnected() |
| 186 | + { |
| 187 | + try |
| 188 | + { |
| 189 | + using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) |
| 190 | + { |
| 191 | + sftp.Connect(); |
| 192 | + |
| 193 | + sftp.CreateDirectory("test_at_dsiposed"); |
| 194 | + |
| 195 | + var files = sftp.EnumerateDirectory(".").Take(1); |
| 196 | + |
| 197 | + sftp.Disconnect(); |
| 198 | + |
| 199 | + // Must fail on disconnected session. |
| 200 | + var count = files.Count(); |
| 201 | + } |
| 202 | + } |
| 203 | + finally |
| 204 | + { |
| 205 | + RemoveAllFiles(); |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | +} |
0 commit comments