Tag: ssh

SCP for C#

是否有一个库提供了在C#中进行SCP传输的能力?

使用SSH.NET库从SFTP下载文件

string host = @”ftphost”; string username = “user”; string password = “********”; string localFileName = System.IO.Path.GetFileName(@”localfilename”); string remoteDirectory = “/export/”; using (var sftp = new SftpClient(host, username, password)) { sftp.Connect(); var files = sftp.ListDirectory(remoteDirectory); foreach (var file in files) { if (!file.Name.StartsWith(“.”)) { string remoteFileName = file.Name; if (file.LastWriteTime.Date == DateTime.Today) Console.WriteLine(file.FullName); File.OpenWrite(localFileName); string sDir […]

SSH.NET不处理我的shell输入命令

我正在使用SSH.NET从C#中的控制台应用程序连接到我的Raspberry Pi。 我想从我自己的流中发送文本,通过StreamWriter写入它。 问题是它什么也没做。 这就像WriteLine(“ls”)不会产生任何影响。 这是代码: using System; using System.IO; using Renci.SshNet; namespace SSHTest { class Program { static void Main(string[] args) { var ssh = new SshClient(“raspberrypi”, 22, “pi”, “raspberry”); ssh.Connect(); var input = new MemoryStream(); var streamWriter = new StreamWriter(input) { AutoFlush = true }; var shell = ssh.CreateShell(input, Console.OpenStandardOutput(), new MemoryStream()); shell.Start(); […]

无法使用SSH.NET库连接到AIX(Unix)框 – 错误:值不能为空

我正在尝试连接到AIX盒并使用SSH.NET库执行一些命令。 以下是代码snipplet KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password); ConnectionInfo connectionInfo = new(ConnectionInfo(servername, 22, username, pauth,kauth); SshClient sshClient = new SshClient(connectionInfo); sshClient.Connect(); SshCommand sshCommand = sshClient.RunCommand(“mpstat”); Console.WriteLine(sshCommand.Result); Console.ReadKey(); 当我尝试在sshClient.Connect()行连接时收到以下exception消息 {“值不能为空。\ r \ nParameter name:data”} 堆栈跟踪是 at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session) at Renci.SshNet.ConnectionInfo.Authenticate(Session session) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect() 我确信我传递的凭据是有效的,因为我能够使用具有相同凭据的PuTTY客户端登录 。 有任何想法吗?

基于SSH.NET的彩色终端模拟器

我正在使用SSH.NET为UWP创建我的终端应用程序。 现在,我已经能够使用库发送/接收数据了,但我想做一些像putty应用程序,它显示不同颜色的文本,甚至能够使用Linux“vi编辑文件“编辑。 有没有办法通过这个库获取颜色/位置信息? 谢谢!

使用Plink.exe测试连接到C#中的SSH

我试图通过plink.exe连接到unix终端。 目标是让我可以将文本读回字符串。 我的困境是我工作的银行使用的是旧的as400类型系统,我们通常通过腻子访问。 我正在尝试开发一个自动化套件,它将与系统连接并运行作业并分析输出等。 所以我想我会通过C#使用plink。 如果我通过命令提示符运行代码,我(大致)得到我需要的文本。 但是我在C#代码中遇到了问题,因为它只是挂起而且我从来没有得到过响应。 我想要的是这样的: 连接到服务器输入命令回读屏幕//更多命令等 这是我到目前为止的代码: class Program { static void Main(string[] args) { ProcessStartInfo psi = new ProcessStartInfo(@”C:\Windows\System32\cmd”); psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; psi.UseShellExecute = false; psi.CreateNoWindow = false; Process process = Process.Start(psi); string cmdForTunnel = @”c:\putty\plink -ssh jonkers@bankhq -pw automationhero”; process.StandardInput.WriteLine(cmdForTunnel); // process.WaitForExit(); Thread.Sleep(30000); string […]

将RSA公钥转换为具有Bouncy Castle的RFC 4716公钥

我希望将RSA公钥转换为可以用作SSH公钥的东西。 目前我有Bouncy Castle为我提供了一个如下所示的公钥: —–BEGIN PUBLIC KEY—– MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq1Y5300i8bN+cI2U3wJE Kh3xG/………jbuz+WB0vvG P25UwCle2k5siVMwbImEYsr+Xt0dsMmGVB3/6MHAqrM3QQdQ8p2E5TyzL+JYa1FT gwIDAQAB —–END PUBLIC KEY—– 我希望它具有与此类似的RFC 4716格式: ssh-rsa AAAAB3NzaC1yc2…….G1p2Ag3mZLFsks7RNHVLgMsGIAikQ== 到目前为止,使用Bouncy Castle的我的代码如下所示: var r = new Org.BouncyCastle.Crypto.Generators.RsaKeyPairGenerator(); r.Init(new KeyGenerationParameters(new SecureRandom(), 2048)); var keys = r.GenerateKeyPair(); var stringWriter = new StringWriter(); var pemWriter = new PemWriter(stringWriter); pemWriter.WriteObject(keys.Private); pemWriter.Writer.Flush(); stringWriter.Close(); PrivateKey = stringWriter.ToString(); stringWriter = new StringWriter(); pemWriter = new […]

用于SSH和Telnet的C#库

我正在寻找一个C#库,它可以在同一个界面下访问SSH和Telnet。 什么是一个好的选择?

在Windows 10更新1803之后,我的程序在从网络共享运行时无法打开套接字

我正在从Windows 10中的共享文件夹运行一些自编写的Winforms .net 3.5应用程序。 一切正常,但在最后一次大更新(1803)后,应用程序不再启动。 似乎程序在尝试打开套接字时崩溃了。 第一个问题是访问数据库时遇到以下exception: 2018-05-03 14:36:32,314 [1] ERROR NHibernate.Transaction.AdoTransaction [(null)] – Begin transaction failed MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. —> System.Net.Sockets.SocketException: invalid argument at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) at MySql.Data.Common.MyNetworkStream.CreateSocketStream(MySqlConnectionStringBuilder settings, IPAddress ip, Boolean unix) at MySql.Data.Common.MyNetworkStream.CreateStream(MySqlConnectionStringBuilder settings, Boolean unix) at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings) at […]

在SSH隧道中创建转发端口

我正在尝试使用SSH.NET从localhost:3306创建隧道localhost:3306到远程计算机上的端口3306: PrivateKeyFile file = new PrivateKeyFile(@” .. path to private key .. “); using (var client = new SshClient(” .. remote server .. “, “ubuntu”, file)) { client.Connect(); var port = new ForwardedPortLocal(3306, “localhost”, 3306); client.AddForwardedPort(port); port.Start(); // breakpoint set within the code here client.Disconnect(); } 当命中断点时, client.IsConnected返回true ,但telnet localhost 3306没有连接。 如果我使用Putty创建连接,并在那里设置相同的隧道,则成功。 我错过了什么?