2
0

ScpClientTests.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. namespace Renci.SshNet.IntegrationTests
  2. {
  3. /// <summary>
  4. /// The SCP client integration tests
  5. /// </summary>
  6. [TestClass]
  7. public class ScpClientTests : IntegrationTestBase, IDisposable
  8. {
  9. private readonly ScpClient _scpClient;
  10. public ScpClientTests()
  11. {
  12. _scpClient = new ScpClient(SshServerHostName, SshServerPort, User.UserName, User.Password);
  13. _scpClient.Connect();
  14. }
  15. [TestMethod]
  16. public void Upload_And_Download_FileStream()
  17. {
  18. var file = $"/tmp/{Guid.NewGuid()}.txt";
  19. var fileContent = "File content !@#$%^&*()_+{}:,./<>[];'\\|";
  20. using var uploadStream = new MemoryStream(Encoding.UTF8.GetBytes(fileContent));
  21. _scpClient.Upload(uploadStream, file);
  22. using var downloadStream = new MemoryStream();
  23. _scpClient.Download(file, downloadStream);
  24. var result = Encoding.UTF8.GetString(downloadStream.ToArray());
  25. Assert.AreEqual(fileContent, result);
  26. }
  27. public void Dispose()
  28. {
  29. _scpClient.Disconnect();
  30. _scpClient.Dispose();
  31. }
  32. }
  33. }