Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Connection Sharing between SSH SCP and SFTP

$
0
0
Hi,

Is there a current method to share a SSH connection between SshClient ScpClient and SFTPClient?

I couldn't find an obvious method so resolved the issue by modifying BaseClient and ScpClient as follows,

BaseClient.cs
///<summary>/// Gets current session.///</summary>public Session Session { get; protectedset; }
ScpClient.cs
public ScpClient(Session establishedSession) : this (establishedSession.ConnectionInfo)
{
    base.Session = establishedSession;
}
To test the modifications I created the following application,

TestProgram.cs
var sshClient = new SshClient(host, username, password);

sshClient.Connect();
var scpClient = new ScpClient(sshClient.Session);

Console.WriteLine("SCP connect? " + scpClient.IsConnected);
FileInfo fileInfo = new FileInfo(@"C:\mybin\temp.exe");
scpClient.Upload(fileInfo, "/home/temp/test/temp.exe");

scpClient.Disconnect();
Thoughts? The TestProgram works fine.

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>