-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransferOptions.cs
executable file
·112 lines (99 loc) · 3.66 KB
/
TransferOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
namespace WinSCP
{
[Guid("6B19CBFA-0D81-4B36-A587-E11AA6A06214")]
[ComVisible(true)]
public enum TransferMode
{
Binary = 0,
Ascii = 1,
Automatic = 2,
}
[Guid("E0F3C3C2-C812-48F1-A711-E0BD0F703976")]
[ComVisible(true)]
public enum OverwriteMode
{
Overwrite = 0,
Resume = 1,
Append = 2,
}
[Guid("155B841F-39D4-40C8-BA87-C79675E14CE3")]
[ClassInterface(Constants.ClassInterface)]
[ComVisible(true)]
public sealed class TransferOptions
{
public bool PreserveTimestamp { get; set; }
public FilePermissions FilePermissions { get; set; }
public TransferMode TransferMode { get; set; }
public string FileMask { get; set; }
public TransferResumeSupport ResumeSupport { get; set; }
public int SpeedLimit { get; set; }
public OverwriteMode OverwriteMode { get; set; }
public TransferOptions()
{
PreserveTimestamp = true;
TransferMode = TransferMode.Binary;
ResumeSupport = new TransferResumeSupport();
OverwriteMode = OverwriteMode.Overwrite;
}
internal string ToSwitches()
{
List<string> switches = new List<string>();
if (FilePermissions != null)
{
switches.Add(Session.FormatSwitch("permissions", FilePermissions.Octal));
}
else
{
switches.Add("-nopermissions");
}
switches.Add(Session.BooleanSwitch(PreserveTimestamp, "preservetime", "nopreservetime"));
string transferModeName;
switch (TransferMode)
{
case TransferMode.Binary:
transferModeName = "binary";
break;
case TransferMode.Ascii:
transferModeName = "ascii";
break;
case TransferMode.Automatic:
transferModeName = "automatic";
break;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not supported", TransferMode));
}
switches.Add(Session.FormatSwitch("transfer", transferModeName));
if (!string.IsNullOrEmpty(FileMask))
{
switches.Add(Session.FormatSwitch("filemask", FileMask));
}
if (ResumeSupport.State != TransferResumeSupportState.Default)
{
switches.Add(Session.FormatSwitch("resumesupport", ResumeSupport.ToString()));
}
if (SpeedLimit > 0)
{
switches.Add(Session.FormatSwitch("speed", SpeedLimit.ToString(CultureInfo.InvariantCulture)));
}
switch (OverwriteMode)
{
case OverwriteMode.Overwrite:
// noop
break;
case OverwriteMode.Resume:
switches.Add(Session.FormatSwitch("resume"));
break;
case OverwriteMode.Append:
switches.Add(Session.FormatSwitch("append"));
break;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not supported", TransferMode));
}
return string.Join(" ", switches.ToArray());
}
}
}