public Upload ( |
||
directoryInfo | The directory info. | |
path | string | The path. |
Résultat | void |
public void Upload(DirectoryInfo directoryInfo, string path)
{
if (directoryInfo == null)
throw new ArgumentNullException("directoryInfo");
if (string.IsNullOrEmpty(path))
throw new ArgumentException("path");
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Send channel command request
channel.SendExecRequest(string.Format("scp -rt \"{0}\"", path));
CheckReturnCode(input);
InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directoryInfo.LastAccessTimeUtc);
SendData(channel, string.Format("D0755 0 {0}\n", Path.GetFileName(path)));
CheckReturnCode(input);
InternalUpload(channel, input, directoryInfo);
SendData(channel, "E\n");
CheckReturnCode(input);
}
}
public void Upload(string fileToUpload,string remotePath, string host) { try { using (ScpClient c = new ScpClient(host, m_userName, m_userPassword)) { Log.DebugFormat("Uploading file: {0} to {1}", fileToUpload, host); c.Connect(); c.Upload(new FileInfo(fileToUpload), remotePath); ExitStatus = 0; c.Disconnect(); } } catch (Exception ex) { Log.ErrorFormat("Failed to upload : {0} to {1} because: {2}", fileToUpload, host, ex); ExitStatus = -1; } }