Its is possible to wrap ssh to scp connection?

Feb 22, 2012 at 1:31 PM

I already used Tamir Gal lib before. I wrote for this my own wraper to convert ssh to scp (regarding connection time). Now i'm about to use ssh.net. Its really nice and clean lib.

The difference between ssh and scp are minor. So it would take only few (compare to tamir gal) lines to edit the code.

If you like, i can post the changes i made to convert ssh to scp. If there is an option, i would like to know...

 

thx

Coordinator
Feb 22, 2012 at 1:45 PM

Hi,

 

If you talking about SCP functionality then I already have it implemented.

If you mean something else, then yes, feel free to send me a changes and I will see what I can do.

 

Thanks,

Oleg

Feb 22, 2012 at 1:58 PM
Edited Feb 23, 2012 at 9:51 AM

 

//Tamir Gal

//SSH Class
public class SshExec : SshBase
{
        public SshExec(SshBase sshBase)  //New Constructor
            : base(sshBase)
        {
        }
}

//SCP Class
public class Scp : SshTransferProtocolBase
{
        public Scp(SshBase sshBase)  //New Constructor
            : base(sshBase)
        {
        }
}

//Scp Base Class
public abstract class SshTransferProtocolBase : SshBase, ITransferProtocol
{
        public SshTransferProtocolBase(SshBase sshBase)  //New Constructor
            : base(sshBase)
        {
        }
}

//SSH und SCP Base
public abstract class SshBase : IDisposable, IEquatable<SshBase>
{
        public SshBase(SshBase otherBase)  //New Constructor
        {
            this.m_host = otherBase.m_host;
            this.m_user = otherBase.m_user;
            this.m_pass = otherBase.m_pass;
            this.m_jsch = otherBase.m_jsch;
            this.m_session = otherBase.m_session;
            this.m_channel = otherBase.m_channel;
        }
}

As you can see, ssh and scp have the same base class.
To Cast ssh and scp to Base i just used

///scp > ssh
var ssh = new ssh(scp as SshBase);

///ssh > scp
var scp = new scp(ssh as SshBase);

//just pseudo code

it is possible to intergrate something like to to the ssh.net? 
I would the it myself, if i could have time!
its quick and dirty but it worked :P

EDIT
So I tried to change this lib myself... got always timeout exception when i try 
to assign Connectioninfo from other (Scp/Ssh) Connection to the new one!
Coordinator
Feb 23, 2012 at 12:43 PM

Hi,

 

I dont see a reason why would you need to do something like this.

You have ScpClient which accept ConnectionInfo class and SshClient which also accept ConnectionInfo so I guess I dont see why would you need to case from SshClient to ScpClient.

 

Thanks,

Oleg

Feb 23, 2012 at 1:13 PM

well if you want to use ssh and scp simultaneously, you have to open two connections at same time. In order to save time and download fast... ?

Coordinator
Feb 23, 2012 at 1:52 PM

That would be the only scenario I thought about :):)

Well, I separated it cause I didn't want put too many functions into one class but you defiantly can merge it together, shouldn't be a problem, but its not as easy as case it one to another one.

Coordinator
Feb 24, 2012 at 2:03 PM

By the way, just an idea, an may be I will do it woo eventually is you can do the following:

Replace this:

public partial class ScpClient : BaseClient

with this:

public partial class ScpClient : SshClient

 

Just change the base class and you should have both functions.

 

Thanks,

Oleg

Feb 28, 2012 at 7:44 AM

good idea...