ssh.net

How to su with SSH.Net?

孤者浪人 提交于 2019-12-12 04:32:46
问题 How can I properly su into root using SSH.Net? This question is similar to: this and this. I couldn't get any of the solutions to the answers to work for me. Here is my code: using (var client = new SshClient("ip", "username", "password")) { client.Connect(); if (client.IsConnected) { var shell = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); var reader = new StreamReader(shell); var writer = new StreamWriter(shell); writer.AutoFlush = true; writer.Write("su - root" + "\n"); var

File empty when downloaded using SSH.NET

江枫思渺然 提交于 2019-12-12 02:06:01
问题 I am using SSH.NET to download file from the SFTP and here is my code: string host = ConfigurationManager.AppSettings["SFTPDomain"]; string username = ConfigurationManager.AppSettings["SFTPUser"]; string password = ConfigurationManager.AppSettings["SFTPPass"]; string remoteFileName = ConfigurationManager.AppSettings["SFTPFileName"].ToString(); using (var sftp = new SftpClient(host, username, password)) { sftp.Connect(); using (var file = File.OpenWrite(FilePath)) { sftp.DownloadFile

Progress bar for parallel file upload with SSH.NET and WPF MVVM

狂风中的少年 提交于 2019-12-10 11:49:20
问题 I am trying to build a WPF application that uses SSH.NET to upload multiple files on a server in parallel and display a progress bar for each of them. In the view I have the following data grid: <DataGrid AlternatingRowBackground="LightGray" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" ItemsSource="{Binding Files, Mode=TwoWay}" SelectedItem="{Binding SelectedFile, Mode=OneWayToSource}"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding

How to run commands on SSH server in C#?

非 Y 不嫁゛ 提交于 2019-12-10 10:15:15
问题 I need to execute this action using a C# code: open putty.exe in the background (this is like a cmd window) login to a remote host using its IP address enter a user name and password execute several commands one after the other. run another command that gets a response telling me that the commands I ran before that where executed successfully So I'm trying to do it like this: ProcessStartInfo proc = new ProcessStartInfo() { FileName = @"C:\putty.exe", UseShellExecute = true, //I think I need

Displaying progress of file download in a ProgressBar with SSH.NET

怎甘沉沦 提交于 2019-12-09 01:21:36
问题 I want to show the progress of a downloading process on my ProgressBar . I tried to do somethings like this code for upload, but I failed. Here is an example of my failed attempts private void button5_Click(object sender, EventArgs e) { Task.Run(() => Download()); } private void Download() { try { int Port = (int)numericUpDown1.Value; string Host = comboBox1.Text; string Username = textBox3.Text; string Password = textBox4.Text; string SourcePath = textBox5.Text; string RemotePath = textBox6

How to write content to file on linux SFTP server using SshClient?

只愿长相守 提交于 2019-12-08 13:54:34
问题 I am dealing with Linux SFTP server using .Net (SshClient) code, so I am creating folder on SFTP server and creating files also. For this I am using following code, using (var client = new SshClient(WebConfigurationManager.AppSettings["SftpServer"], WebConfigurationManager.AppSettings["SftpUserName"], WebConfigurationManager.AppSettings["SftpPassword"])) { client.Connect(); if (client.IsConnected) { // Check if the Folder Already Exists var ifExists = client.RunCommand("cat /etc/passwd | grep

How can I add SSH.NET NuGet packages into my Azure Functions v2.0?

柔情痞子 提交于 2019-12-08 04:58:58
问题 my Azure function is v2. I have added <PackageReference Include="SSH.NET" Version="2016.1.0" /> into ItemGroup in function.proj. However, #r "Renci.SshNet" is NOT working. #r "D:\home\site\wwwroot\bin\Renci.SshNet.dll" is NOT working either. Because there is no bin folder under wwwroot. What is the normal way to include Renci.SshNet? Regards, Zhenyu my function.proj screenshot 回答1: You can add bin folder under wwwroot and drag the dll to it by "Advanced tools(kudu)" under azure function

SFTP - check free space available

扶醉桌前 提交于 2019-12-08 04:18:08
问题 I'm using Renci SSH.NET library for secure ftp connection. Now I have to check free disk space available on remote SFTP server. How can I do this? 回答1: As Eugene commented, SFTP protocol version 6 lets one check available space ( SSH_FXP_EXTENDED request name space-available ). But Renci SSH.NET library supports SFTP protocol version 3 only. Also worth noting that most SSH/SFTP servers (notably OpenSSH, as the one the most widespread) support SFTP version 3 only too. So client-side support

SSH.NET: Is it possible to upload files using SFTP and preserve the file dates from source files?

被刻印的时光 ゝ 提交于 2019-12-08 02:32:24
问题 Currently, I am using the Renci SSH.NET library to upload files to a Unix server using SFTP. One thing that I don't like is that after uploading files, the creation- and modified dates are altered to the time when the upload took place. I would like to preserve the original file dates from the source files, is that possible? 回答1: The SSH.NET library won't do it for you automatically. You have to code it. There are SftpClient.SetLastWriteTime and SftpClient.SetLastWriteTimeUtc methods. But

Renci SSH.NET: Is it possible to create a folder containing a subfolder that does not exist

时光怂恿深爱的人放手 提交于 2019-12-07 17:47:45
问题 I am currently using Renci SSH.NET to upload files and folders to a Unix Server using SFTP, and creating directories using sftp.CreateDirectory("//server/test/test2"); works perfectly, as long as the folder "test" already exists. If it doesn't, the CreateDirectory method fails, and this happens everytime when you try to create directories containing multiple levels. Is there an elegant way to recursively generate all the directories in a string? I was assuming that the CreateDirectory method