ssh.net

What is the difference between SftpClient.UploadFile and SftpClient.WriteAllBytes?

只愿长相守 提交于 2019-12-05 18:18:02
I am observing some strange behaviour when I use SSH.NET to transfer files with SFTP. I am using SFTP to transfer XML files to another service (which I don't control) for processing. If I use SftpClient.WriteAllBytes the service complains the file is not valid XML. If I first write to a temporary file and then use SftpClient.UploadFile the transfer is successful. What's happening? Using .WriteAllBytes : public void Send(string remoteFilePath, byte[] contents) { using(var client = new SftpClient(new ConnectionInfo(/* username password etc.*/))) { client.Connect(); client.WriteAllBytes

SSH.NET Upload whole folder

馋奶兔 提交于 2019-12-05 06:01:42
I use SSH.NET in C# 2015. With this method I can upload a file to my SFTP server. public void upload() { const int port = 22; const string host = "*****"; const string username = "*****"; const string password = "*****"; const string workingdirectory = "*****"; string uploadfolder = @"C:\test\file.txt"; Console.WriteLine("Creating client and connecting"); using (var client = new SftpClient(host, port, username, password)) { client.Connect(); Console.WriteLine("Connected to {0}", host); client.ChangeDirectory(workingdirectory); Console.WriteLine("Changed directory to {0}", workingdirectory);

SSH.NET CreateShellStream()

耗尽温柔 提交于 2019-12-04 22:32:16
I am building an application, SWSH, which is a ssh client. I am having trouble using the CreateShellStream() function. My code: using (var ssh = new SshClient(ccinfo)) { var keepgoing = true; ssh.Connect(); string terminalName = "xterm-256color"; uint columns = 80; uint rows = 160; uint width = 80; uint height = 160; // arbitrarily chosen int bufferSize = 500; IDictionary<Renci.SshNet.Common.TerminalModes, uint> terminalModeValues = null; var actual = ssh.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues); //Read Thread new System.Threading.Thread(()

How to save downloaded files in MemoryStream when using SSH.NET

南笙酒味 提交于 2019-12-04 21:32:52
问题 I am using SSH.NET library to download files. I want to save the downloaded file as a file in memory, rather than a file on disk but it is not happening. This is my code which works fine: using (var sftp = new SftpClient(sFTPServer, sFTPPassword, sFTPPassword)) { sftp.Connect(); sftp.DownloadFile("AFile.txt", System.IO.File.Create("AFile.txt")); sftp.Disconnect(); } and this is the code which doesn't work fine as it gives 0 bytes stream. using (var sftp = new SftpClient(sFTPServer,

SSH.NET Library - SshClient.Dispose(), public connection

倖福魔咒の 提交于 2019-12-04 19:45:13
I have 2 problems with using SSH.NET library. I would like to create SSH connection and then disconnect. But if I start asynchronous read, disconnecting causes problems. My program simply freezes when I try to end a connection. public void button1_Click(object sender, EventArgs e) { var ssh = new SshClient(IP, UserName, Password); ssh.Connect(); var stream = ssh.CreateShellStream("anything", 80, 24, 800, 600, 4096); byte[] buffer = new byte[1000]; stream.BeginRead(buffer, 0, buffer.Length, null, null); stream.DataReceived += new EventHandler<Renci.SshNet.Common.ShellDataEventArgs>( (s, ex) =>

SSH.NET SFTP Get a list of directories and files recursively

大憨熊 提交于 2019-12-04 17:42:02
问题 I am using Renci.SshNet library to get a list of files and directories recursively by using SFTP. I can able to connect SFTP site but I am not sure how to get a list of directories and files recursively in C#. I haven't found any useful examples. Has anybody tried this? If so, can you post some sample code about how to get these files and folders recursively. Thanks, Prav 回答1: This library has some quirks that make this recursive listing tricky because the interaction between the

Getting full command output from ShellStream of C# SSH.NET

こ雲淡風輕ζ 提交于 2019-12-04 11:51:19
Using Renci.SshNet library. I am trying to execute some commands. After executing "command 1", I am executing "command 2" which takes more time. I am only getting the first line of the output. ( reader.ReadToEnd() is not working in a proper way). I also tried while (!reader.EndOfStream){ } with no luck. I think it is because the delay of the response from server. When there is no response the stream read nothing and finishes. I found a solution String tmp; TimeSpan timeout = new TimeSpan(0, 0, 3); while ((tmp = s.ReadLine()) != null) { Console.WriteLine(tmp); } But this is not professional. I

Providing input/subcommands to a command (cli) executed with SSH.NET SshClient.RunCommand

一世执手 提交于 2019-12-04 01:46:56
问题 I created a program using Renci SSH.NET library. Its sending all the commands and reading the result normally. However, when I send the command below: client.RunCommand("cli"); The program hangs on this line indefinitely. Any explanation of what is happening? 回答1: AFAIK, cli is a kind of a shell/interactive program. So I assume you have tried to do something like: client.RunCommand("cli"); client.RunCommand("cli subcommand"); That's wrong. cli will keep waiting for subcommands and never exit,

Is it possible to work on normal (not SFTP) FTP on Renci SSH.NET? - which client to use?

不想你离开。 提交于 2019-12-04 01:09:47
问题 I am using Renci SSH.NET, but trying to test on a FTP (not SFTP site). I did get this working with WinSCP - but cannot get it to work on Renci - WinSCP allows me to set the protocol to either FTP or SFTP - I think this is the issue - I am prompted for No suitable authentication method found to complete authentication (publickey,keyboard-interactive). How do I turn off SFTP (and just use FTP) on Renci SSH.NET? I tried Dim c As Renci.SshNet.SftpClient / ScpClient/ BaseClient / NetConfClient

Authentication with PPK key in SSH.NET

为君一笑 提交于 2019-12-03 23:13:26
问题 I'm creating a window service for downloading files from an SFTP server. For that I'm using Renci.SshNet , Renci.SshNet.Common and Renci.SshNet.Sftp . I have this code: String Host = "HostName"; int Port = 22; String RemoteFileDirectory = Convert.ToString(ConfigurationManager.AppSettings["SourcePath"]); String Username = "UserName"; String Password = "*******"; var KeybasedMethod = new KeyboardInteractiveAuthenticationMethod(Username); KeybasedMethod.AuthenticationPrompt += (sender, e) => { e