SftpClientTest.RenameFileAsync.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
  2. {
  3. /// <summary>
  4. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  5. /// </summary>
  6. public partial class SftpClientTest : IntegrationTestBase
  7. {
  8. [TestMethod]
  9. [TestCategory("Sftp")]
  10. public async Task Test_Sftp_RenameFileAsync()
  11. {
  12. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  13. {
  14. await sftp.ConnectAsync(default);
  15. string uploadedFileName = Path.GetTempFileName();
  16. string remoteFileName1 = Path.GetRandomFileName();
  17. string remoteFileName2 = Path.GetRandomFileName();
  18. CreateTestFile(uploadedFileName, 1);
  19. using (var file = File.OpenRead(uploadedFileName))
  20. {
  21. using (Stream remoteStream = await sftp.OpenAsync(remoteFileName1, FileMode.CreateNew, FileAccess.Write, default))
  22. {
  23. await file.CopyToAsync(remoteStream, 81920, default);
  24. }
  25. }
  26. await sftp.RenameFileAsync(remoteFileName1, remoteFileName2, default);
  27. File.Delete(uploadedFileName);
  28. sftp.Disconnect();
  29. }
  30. RemoveAllFiles();
  31. }
  32. [TestMethod]
  33. [TestCategory("Sftp")]
  34. [Description("Test passing null to RenameFile.")]
  35. [ExpectedException(typeof(ArgumentNullException))]
  36. public async Task Test_Sftp_RenameFileAsync_Null()
  37. {
  38. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  39. {
  40. await sftp.ConnectAsync(default);
  41. await sftp.RenameFileAsync(null, null, default);
  42. sftp.Disconnect();
  43. }
  44. }
  45. }
  46. }