Tag: ssh.net

Renci SSH.NET:是否可以创建包含不存在的子文件夹的文件夹

我目前正在使用Renci SSH.NET使用SFTP将文件和文件夹上传到Unix服务器,并使用创建目录 sftp.CreateDirectory(“//server/test/test2”); 只要文件夹“test”已经存在,它就能完美运行。 如果没有, CreateDirectory方法将失败,并且每次尝试创建包含多个级别的目录时都会发生这种情况。 是否有一种优雅的方式来递归生成字符串中的所有目录? 我假设CreateDirectory方法自动执行此操作。

C#通过SSH.NET发送Ctrl + Y.

我目前正在使用SSH.net并尝试连接到Avaya交换机。 我的代码如下所示: using (var client = new SshClient(ip, username, password)) { client.Connect(); //Sending CTRL+Y SshCommand x = client.RunCommand(“enable”); client.Disconnect(); } 我还没有找到解决方案。 是否有任何解决方法或命令可用于发送我的CTRL + Y ?

在C#中通过SSH.NET进行多跳SSH

我正在使用SSH到Linux机器,并再次从那里想要SSH到另一台Linux机器来执行几个Perforce任务。 using (SshClient ssh = new SshClient(“ip address”,”username”, “pwd”)) { ssh.Connect(); command = ssh.CreateCommand(“ssh hostname”); result = command.Execute(); Console.WriteLine(result); } ssh hostname是密码少 ssh的地方。 如何控制第二个SSH会话并将命令传递给它? 甚至探索了CreateShell函数,但似乎没有建议自动化。

在C#中使用SSH.NET SFTP下载目录

我正在使用Renci.SSH和C#从Windows机器连接到我的Unix服务器。 当目录内容只是文件时,我的代码按预期工作,但如果目录包含文件夹,我会得到这个 Renci.SshNet.Common.SshException:’失败’ 这是我的代码,如何更新此代码以下载目录(如果存在) private static void DownloadFile(string arc, string username, string password) { string fullpath; string fp; var options = new ProgressBarOptions { ProgressCharacter = ‘.’, ProgressBarOnBottom = true }; using (var sftp = new SftpClient(Host, username, password)) { sftp.Connect(); fp = RemoteDir + “/” + arc; if (sftp.Exists(fp)) fullpath = fp; else fullpath […]

SSH.NET:是否可以使用SFTP上传文件并保留源文件中的文件日期?

目前,我使用Renci SSH.NET库使用SFTP将文件上传到Unix服务器。 我不喜欢的一件事是,在上传文件后,创建和修改日期会更改为上传时间。 我想保留源文件中的原始文件日期,这可能吗?

使用SSH.Net下载并返回非阻塞数据流

我正在使用ssh.net库执行SFTP操作以处理大型数据文件( > = 500MB ) 我遇到了如何以非阻塞方式返回数据的问题。 ftpClient.DownloadFile()方法签名是正确的,当写入文件或者有某种方式我可以实例化流,但是当我想要在不阻塞的情况下返回流时遇到如何使用它的问题。 到目前为止我看到的所有示例都是将下载文件写入文件流。 什么都不会只返回一个流 使用.Net的内置FTP,您只需使用response.GetResponseStream() ,它会回送数据,而不会阻塞。 在return语句中使用它的唯一方法是写入临时文件。 但这导致它成为阻塞操作。 var tmpFilename = “temp.dat”; int bufferSize = 4096; var sourceFile = “23-04-2015.dat”; using (var stream = System.IO.File.Create(tmpFilename , bufferSize, System.IO.FileOptions.DeleteOnClose)) { sftpClient.DownloadFile(sourceFile, stream); return stream; } 我不希望它阻止但是要回流数据。 我也想避免创建一个临时文件。 是否有替代实现使其回流数据? 或者是否有可以实例化的替代流( MemoryStream除外),它可以用于大文件?

使用SSH.NET恢复网络连接后自动恢复SFTP下载

我正在使用SSH.NET库来创建SFTP客户端。 如果网络连接在此超时内再次可用,我需要恢复下载。 我使用下面提到的方法,如许多例子所示。 PrivateKeyFile ObjPrivateKey = new PrivateKeyFile(keyStream); PrivateKeyAuthenticationMethod ObjPrivateKeyAutentication = new PrivateKeyAuthenticationMethod(username, ObjPrivateKey); var connectionInfo = new ConnectionInfo(hostAddress, port, username, ObjPrivateKeyAutentication); try { using (var client = new SftpClient(connectionInfo)) { client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(10); client.Connect(); if (!client.IsConnected) { return false; } if (!client.Exists(source)) { return false; } var fileName = Path.GetFileName(source); using (var fs = […]

使用SSH.NET将文件从Windows移动到UNIX服务器时,修改日期时间会更改

我在我的C#应用​​程序中使用SSH.NET将文件从Windows复制到UNIX服务器,我有几个场景: 在UNIX服务器目录中, 如果要复制的文件不存在 ,则将文件复制到UNIX服务器时修改的日期时间更改为复制的日期时间 ? 这是正确的,因为修改后的日期时间不应该改变吗? 在UNIX Server目录中, 如果要复制的文件已存在 ,则在复制在UNIX服务器路径中替换的同一文件时,文件的修改日期时间不会更改 ! 我对这个修改过的日期时间感到困惑,因为我在这篇文章中读过SSH.NET错误地做了,这应该是正确的吗? 对于那些要求提供代码的人,这里有: private static int UploadFileToSFTP (string localFileFullPath, string uploadPath) { try { Log.Debug(“Inside Utilities.UploadFileToSFTP() with localFileFullPath=” + localFileFullPath + “, and remoteUploadPath=” + uploadPath); Log.Debug(“Uploading File : ” + uploadPath); using (FileStream fs = new FileStream(localFileFullPath, FileMode.Open)) { Log.Debug(“Checking if path: ” + […]

在SSH.NET中执行长时间命令并在TextBox中连续显示结果

有没有办法执行Linux命令并在PuTTY等Windows应用程序的文本框中显示结果。 例如,我正在尝试执行以下命令 wget http://centos-webpanel.com/cwp-latest sh cwp-latest 使用以下代码 SshClient sshclient = new SshClient(IPtxtBox.Text, UserNameTxt.Text, PasswordTxt.Text); sshclient.Connect(); ShellStream stream = sshclient.CreateShellStream(“customCommand”, 80, 24, 800, 600, 1024); resultTxt.Text = SSHCommand.SendCommand(stream, “wget http://centos-webpanel.com/cwp-latest && sh cwp-latest”); private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream) { writer.WriteLine(cmd); while (stream.Length == 0) Thread.Sleep(500); } private static string ReadStream(StreamReader reader) { […]

SSH.NET上传整个文件夹

我在C#2015中使用SSH.NET。 通过这种方法,我可以将文件上传到我的SFTP服务器。 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); […]