Renci.SshNet.ScpClient.Upload C# (CSharp) Method

Upload() public method

Uploads the specified directory to the remote host.
fileSystemInfo is null or empty.
public Upload ( DirectoryInfo directoryInfo, string path ) : void
directoryInfo System.IO.DirectoryInfo The directory info.
path string The path.
return 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);
            }
        }

Same methods

ScpClient::Upload ( FileInfo fileInfo, string path ) : void
ScpClient::Upload ( Stream source, string path ) : void

Usage Example

Exemplo n.º 1
2
 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;
     }
 }
All Usage Examples Of Renci.SshNet.ScpClient::Upload