TransferOptions.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Runtime.InteropServices;
  5. namespace WinSCP
  6. {
  7. [Guid("6B19CBFA-0D81-4B36-A587-E11AA6A06214")]
  8. [ComVisible(true)]
  9. public enum TransferMode
  10. {
  11. Binary = 0,
  12. Ascii = 1,
  13. Automatic = 2,
  14. }
  15. [Guid("155B841F-39D4-40C8-BA87-C79675E14CE3")]
  16. [ClassInterface(Constants.ClassInterface)]
  17. [ComVisible(true)]
  18. public sealed class TransferOptions
  19. {
  20. public bool PreserveTimestamp { get; set; }
  21. public FilePermissions FilePermissions { get; set; }
  22. public TransferMode TransferMode { get; set; }
  23. public string FileMask { get; set; }
  24. public TransferResumeSupport ResumeSupport { get; private set; }
  25. public TransferOptions()
  26. {
  27. PreserveTimestamp = true;
  28. TransferMode = TransferMode.Binary;
  29. ResumeSupport = new TransferResumeSupport();
  30. }
  31. internal string ToSwitches()
  32. {
  33. List<string> switches = new List<string>();
  34. if (FilePermissions != null)
  35. {
  36. switches.Add(Session.FormatSwitch("permissions", FilePermissions.Octal));
  37. }
  38. else
  39. {
  40. switches.Add("-nopermissions");
  41. }
  42. switches.Add(Session.BooleanSwitch(PreserveTimestamp, "preservetime", "nopreservetime"));
  43. string transferModeName;
  44. switch (TransferMode)
  45. {
  46. case TransferMode.Binary:
  47. transferModeName = "binary";
  48. break;
  49. case TransferMode.Ascii:
  50. transferModeName = "ascii";
  51. break;
  52. case TransferMode.Automatic:
  53. transferModeName = "automatic";
  54. break;
  55. default:
  56. throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not supported", TransferMode));
  57. }
  58. switches.Add(Session.FormatSwitch("transfer", transferModeName));
  59. if (!string.IsNullOrEmpty(FileMask))
  60. {
  61. switches.Add(Session.FormatSwitch("filemask", FileMask));
  62. }
  63. if (ResumeSupport.State != TransferResumeSupportState.Default)
  64. {
  65. switches.Add(Session.FormatSwitch("resumesupport", ResumeSupport.ToString()));
  66. }
  67. return string.Join(" ", switches.ToArray());
  68. }
  69. }
  70. }