public void Upload(string localPath, string remotePath, bool recursive, bool preserveTime,
Cancellation cancellation,
SCPFileTransferProgressDelegate progressDelegate)
{
if (!IsAscii(remotePath))
throw new SCPClientException("Remote path must consist of ASCII characters.");
bool isDirectory = Directory.Exists(localPath);
if (!File.Exists(localPath) && !isDirectory)
throw new SCPClientException("File or directory not found: " + localPath);
if (isDirectory && !recursive)
throw new SCPClientException("Cannot copy directory in non-recursive mode");
string absLocalPath = Path.GetFullPath(localPath);
string command = "scp -t ";
if (recursive)
command += "-r ";
if (preserveTime)
command += "-p ";
command += EscapeUnixPath(remotePath);
using (SCPChannelStream stream = new SCPChannelStream()) {
stream.Open(_connection, command, _protocolTimeout);
CheckResponse(stream);
if (isDirectory) { // implies recursive mode
UploadDirectory(absLocalPath, stream, preserveTime, cancellation, progressDelegate);
}
else {
UploadFile(absLocalPath, stream, preserveTime, cancellation, progressDelegate);
}
}
}