Skip to content

Commit e83486c

Browse files
committed
Do not create extra directory level when uploading the content of a directory.
Fixes issue #128.
1 parent 0ac28d2 commit e83486c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Renci.SshNet/ScpClient.NET.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ public void Upload(DirectoryInfo directoryInfo, string path)
6363
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
6464
channel.Open();
6565

66-
// Send channel command request
66+
// start recursive upload
6767
channel.SendExecRequest(string.Format("scp -rt \"{0}\"", path));
6868
CheckReturnCode(input);
6969

70+
// set last write and last access time on specified remote path
7071
InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directoryInfo.LastAccessTimeUtc);
71-
SendData(channel, string.Format("D0755 0 {0}\n", Path.GetFileName(path)));
72+
SendData(channel, string.Format("D0755 0 {0}\n", "."));
7273
CheckReturnCode(input);
7374

75+
// recursively upload files and directories in specified remote path
7476
InternalUpload(channel, input, directoryInfo);
7577

78+
// terminate upload of specified remote path
7679
SendData(channel, "E\n");
7780
CheckReturnCode(input);
7881
}
@@ -156,7 +159,7 @@ private void InternalUpload(IChannelSession channel, Stream input, DirectoryInfo
156159
var directories = directoryInfo.GetDirectories();
157160
foreach (var directory in directories)
158161
{
159-
InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directoryInfo.LastAccessTimeUtc);
162+
InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directory.LastAccessTimeUtc);
160163
SendData(channel, string.Format("D0755 0 {0}\n", directory.Name));
161164
CheckReturnCode(input);
162165

src/Renci.SshNet/ScpClient.cs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace Renci.SshNet
1212
/// <summary>
1313
/// Provides SCP client functionality.
1414
/// </summary>
15+
/// <remarks>
16+
/// More information on the SCP protocol is available here:
17+
/// https://github.com/net-ssh/net-scp/blob/master/lib/net/scp.rb
18+
/// </remarks>
1519
public partial class ScpClient : BaseClient
1620
{
1721
private static readonly Regex FileInfoRe = new Regex(@"C(?<mode>\d{4}) (?<length>\d+) (?<filename>.+)");

0 commit comments

Comments
 (0)