Same problem here:
trying to copy from Win7 into subfolder in Mac OS X 10.7.5 (11G63)
with
using (var transfer = new ScpClient(connectionInfo))
{
transfer.Connect();
transfer.Upload(new System.IO.DirectoryInfo("D:\\Temp\\Test"), "test/testsub");
transfer.Disconnect();
}
results in "scp: error: unexpected filename: test/testsub
Same with fully qualified path: transfer.Upload(new System.IO.DirectoryInfo("D:\\Temp\\Test"), "/Users/demo/test/testsub");
results in "scp: error: unexpected filename: /Users/Demo/test/testsub
Changing InternalUpload to
private void InternalUpload(ChannelSession channel, PipeStream input, DirectoryInfo directoryInfo, string directoryName)
{
this.InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directoryInfo.LastAccessTimeUtc);
var dirPath = Path.GetFileName(directoryName);
this.SendData(channel, string.Format("D0755 0 {0}\n", dirPath ));
this.CheckReturnCode(input);
// Upload files
var files = directoryInfo.GetFiles();
foreach (var file in files)
{
this.InternalUpload(channel, input, file, Path.Combine(dirPath, file.Name));
}
// Upload directories
var directories = directoryInfo.GetDirectories();
foreach (var directory in directories)
{
this.InternalUpload(channel, input, directory,
Path.Combine(dirPath,directory.Name));
}
this.SendData(channel, "E\n");
this.CheckReturnCode(input);
}
does the trick ... mostly.
It however still fails if the target path consists of more than one folder and the first folder of the chain is missing in the target system.
doing an explicit
channel.SendExecRequest(string.Format("mkdir -p \"{0}\"", directoryName));
within its own channel
using (var input1 = new PipeStream())
using (var channel1 = this.Session.CreateChannel<ChannelSession>())
{
channel1.DataReceived += delegate(object sender, Common.ChannelDataEventArgs e)
{
input1.Write(e.Data, 0, e.Data.Length);
input1.Flush();
};
channel1.Open();
channel1.SendExecRequest(string.Format("mkdir -p \"{0}\"", directoryName));
channel1.Close();
}
solves this as well - not overly elegant, but functional :)