|
i would like to thank you for this great work, we need to create biztalk adapter to connect to SSH server,
we may use ur library, but realy i have some general questions:
what do you mean by SFTP is this just naming convention or related to FTP
are all communications done over the SSH, and can i use this library on win platform for the client and server,
finally i appreciate if you can explain me the things that i have to understand before start using it.
please forgive me for this questions but i hope to hear from you
thanks
alaa jarrah
|
|
|
|
|
ajarrah wrote: what do you mean by SFTP is this just naming convention or related to FTP
SFTP stand for "SSH file transfer protocol", it is a standard protocol under SSH. If you google for it you'll find planty of info.
ajarrah wrote: are all communications done over the SSH
Yes.
ajarrah wrote: and can i use this library on win platform for the client and server
SharpSSH implements only the client side of SSH. You may look for SSH servers for windows, i'm sure you'll find planty (e.g. WinSSHd, FreeSSHd, OpenSSH).
SharpSSH is a .NET lib so of course it runs under windows.
ajarrah wrote: finally i appreciate if you can explain me the things that i have to understand before start using it.
SharpSSH comes with lots of example. Just download it from my home page and take a look at the sample applications.
|
|
|
|
|
Hi Tamir,
Thanks for this library!!
I'm trying to send a regular system.io.stream using SFTP. The sftp.put function only handles the ported java.io.InputStream.
How can I convert my stream into the java.io.InputStream?
Best regards,
Marco
|
|
|
|
|
Hi Marco,
Here is a wrapper you can use and pass to sftp.put:
using Tamir.SharpSsh.java.io;
namespace Tamir.Streams
{
public class InputStreamWrapper : InputStream
{
System.IO.Stream s;
public InputStreamWrapper(System.IO.Stream s)
{
this.s = s;
}
public override int Read(byte[] buffer, int offset, int count)
{
return s.Read(buffer, offset, count);
}
}
}
However, please note that this approach of passing a stream instead of a file was never tested.
Good luck,
Tamir
|
|
|
|
|
Hi Tamir,
Thanks for the solution. It seems to work. I have applied the same for reading a file.
I did notice another thing, When you don't explicitly close the connection and the session object runs out of scope, then the connection is not automatically closed and a thread (session.run) is not stopped.
Best regards,
Marco
|
|
|
|
|
Is it possible to throw oub such exception like "Invalid user", "Invalid password" or "Invliad public key" instead of "Auth Fail"?
Thanks
|
|
|
|
|
Hi,
I may take a look at it in a future version but I can't commit on anything.
The thing is that a user may try several authentication methods before failing.
In such case, we will need to agregate all failed attempts in the Exception.
Also, there were some talks on the JSch mailing lists about this topic, and if they will come up with a solution of their own, I prefer conforming to their approch for compatibility.
Cheers,
Tamir
|
|
|
|
|
I keep getting "Invaid private key" (including the spelling error). The key is valid, because I can log in to the server manually.
I was looking through the code and it's looking for "BEGI" in the private key file. What is this and how can I make it get past this so I can log in?
Thanks!
|
|
|
|
|
The key file must be in the OpenSSH format.
All OpenSSH private keys start with a "-----BEGIN" string.
If your key is not in OpenSSH format it may be converted to OpenSSH format using the 'ssh-keygen' util available in OpenSSH or using the keygen util of your SSH client.
|
|
|
|
|
Thanks! It's accepting the key now (I'm assuming it doesn't affect the value even though it looks different). Now I'm getting this error when trying to connect:
+ ex {"Session.connect: System.NullReferenceException: Object reference not set to an instance of an object.
at Tamir.SharpSsh.jsch.jce.HMACMD5.update(Byte[] foo, Int32 s, Int32 l)
at Tamir.SharpSsh.jsch.jce.HMACMD5.update(Int32 i)
at Tamir.SharpSsh.jsch.Session.read(Buffer buf)
at Tamir.SharpSsh.jsch.UserAuth.start(Session session)
at Tamir.SharpSsh.jsch.UserAuthNone.start(Session session)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)"} System.Exception
|
|
|
|
|
Hi,
This is very strange error.
Can you please provide more info?
Which server do you connect to?
Do you get this error only with this server? Or do you get it with any server you connect?
Which version of SharpSSH?
Do you get this when using publickey authetication? or also with password authentication?
Any other useful info?
Thanks,
Tamir
|
|
|
|
|
Hi, i'm gettin the "invalid private key" error, i've generate a private key with the puttygen (SSH-2 RSA 1024 bits) and i can connect manually to the server but when i put the private key in the addIdentity method it throws me the private key error. please help...
|
|
|
|
|
Hey kiglid,
Were you able to get around the error you mentioned.
ex {"Session.connect: System.NullReferenceException: Object reference not set to an instance of an object.
I am getting a similar one for a openssh DSA key
e System.NullReferenceException: Object reference not set to an instance of an o
bject.
at Tamir.SharpSsh.jsch.Util.stripLeadingZeros(Byte[] a)
at Tamir.SharpSsh.jsch.jce.SignatureDSA.setPrvKey(Byte[] x, Byte[] p, Byte[]
q, Byte[] g)
at Tamir.SharpSsh.jsch.IdentityFile.getSignature_dss(Session session, Byte[]
data)
Tamir,
Any ideas??
Raj
|
|
|
|
|
Hi Tamir,
I have one query.. just to have clear idea about Expect function.
If I set
shell.ExpectPattern = userName + ">";
then can I use this
string returnedString = shell.Expect();
or I must use
string returnedString = shell.Expect(userName + ">");
again and again???
Somehow, when I am trying to execute a batch of commands, the process gets stuck.
I have seen the strings returned are sometimes not proper text messages (as you might see them on an tty client) and I see blocks of characters, and so it might be possible that the pattern use to expect is not found (due to garbled string).
Any idea why the string is corrupted?
|
|
|
|
|
If you set the ExpectPattern property it should be safe to ise the Expect() function.
Nayan Choudhary wrote: and so it might be possible that the pattern use to expect is not found (due to garbled string).
Does the garbled string have obvious pattern? Maybe you can add it to the Expect pattern in a way that it will match both garbelled and non garbelled responses.
|
|
|
|
|
I don't know if the garbled string has the pattern, the way you mentioned (I'm sorry, I couldn't understand your answer clearly).
The string gets corrupted randomly with blocks of special characters. I don't know what should be the pattern to avoid/remove it. Anyways, let me experiment for some time to find when does it happen.
Thanks a lot!
Nayan
|
|
|
|
|
Hi Tamir,
I am finding serious issues of string returned from Expect function.
I very often see the pattern - multiple spaces followed by multiple backspace char, same in number - in between the strings returned. Also, sometimes the prompt is breaking the command in the string returned.
I cannot show the pattern here because the editor takes it normal keystrokes. That means, visually the data is correct, but the binary data in the string has these chars.
Example:
I want to run command
\ls -lt /myFolder/file_* | tr -s " " " " | cut -d " " -f 5,6,7,8,9
multiple times (actually polling the files - any better idea on how to poll unix files?).
What I see on the screen is
\ls -lt /myFolder/file_* | tr -s <br />
cbwrk11@hpxc7601!M3G:cbwrk11> /file_* | tr -s " <" " " | cut -d " " -<br />
cbwrk11@hpxc7601!M3G:cbwrk11> " " " " | cut -d " " -f 5,6,7,,9<br />
myFolder/file_* not found<br />
cbwrk11@hpxc7601!M3G:cbwrk11>\ls -lt /myFolder/file_* | tr -s <br />
cbwrk11@hpxc7601!M3G:cbwrk11> /file_* | tr -s " < " " " | cut -d " " -<br />
cbwrk11@hpxc7601!M3G:cbwrk11> " " " " | cut -d " " -f 5,6,7,,9<br />
/myFolder/file_* not found<br />
cbwrk11@hpxc7601!M3G:cbwrk11>
[Here you cannot see the backspace chars. But as I pasted them in this editor, I can see them here. Also note that there is a '<' char in between the strings which is unexpected.]
The execution is working fine. But the string returned isn't correct, thus not useful for logging what happened.
Please, can you suggest something?
Thanks a million!
Nayan
|
|
|
|
|
Hi Nayan,
May I suggest taking different approach than using Expect?
Can you please try using Exec channel instead of Shell channel (check out my samples for more info)?
When running a remote program using exec, the output comes with no terminal escape characters.
However exec channles are not always supported by servers and you get less script wise capabilities compared to Expect.
Please have it ago.
Thanks,
Tamir
|
|
|
|
|
Hi Tamir,
As I see your examples, I understand the idea of using Exec channel.
But I see very less documentation (for most of the things) in order to experiment freely. Can you provide any link or write about the conditions when servers don't support exec channel and what exactly are the reduced scripting capabilities?
Thanks for the help! I really appreciate it.
Nayan
|
|
|
|
|
ssh exec channels are usually used for executing a single remote progrem and interacting with its stdout, stdin, stderr, etc.
For example the SCP implementation is using an exec channel to execute a remote "scp -t" command. You may take a look at my Scp class for more info.
However when using ssh exec you lose the context of a Shell. Each exec command is run independently of other commands. This means (for example) that if you set env variables in a command they will be lost upon the next exec command.
OpenSSH supports exec channels, but some other servers doesn't (can't really remember any names at the moment, sorry).
|
|
|
|
|
Can you tell me what is wrong?
Trying SharpSSH binaries got this error
Connecting...Auth fail
SharpSSH-1.1.1.11
User and password works in putty
Regards
Ezequiel
|
|
|
|
|
Is password authentication enabled on the server? For example, on OpenSSH server you should have the following line in the ssh_config file:
PasswordAuthentication yes
If password authentication is enabled, it will be useful if you could post the output of the following OpenSSH command:
ssh -vv [serverHost]
|
|
|
|
|
ssh -vv linuxba01
OpenSSH_3.8.1p1 FreeBSD-20060123, OpenSSL 0.9.7e-p1 25 Oct 2004
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to linuxba01.ar.lumina.net [10.0.0.43] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/identity type -1
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_3.4p1
debug1: match: OpenSSH_3.4p1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.8.1p1 FreeBSD-20060123
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-dss,ssh-rsa
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 119/256
debug2: bits set: 503/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'linuxba01.ar.lumina.net' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:7
debug2: bits set: 505/1024
debug1: ssh_dss_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/identity (0x0)
debug2: key: /root/.ssh/id_rsa (0x806e4c0)
debug2: key: /root/.ssh/id_dsa (0x0)
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
root@linuxba01.ar.lumina.net's password:
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: ssh_session2_setup: id 0
debug2: channel 0: request pty-req
debug2: channel 0: request shell
debug2: fd 3 setting TCP_NODELAY
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 131072
Last login: Mon Oct 30 11:25:39 2006 from nop3
[root@linuxba01 root]# exit
logout
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
Connection to linuxba01.ar.lumina.net closed.
debug1: Transferred: stdin 0, stdout 0, stderr 47 bytes in 9.7 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 4.9
debug1: Exit status 0
|
|
|
|
|
I don't see any issues with this output, which may indicate a SharpSSH bug.
May I send you a debug version of SharpSSH, which will add some prints to see what's going on?
If so, please drop me a line at [SharpSSH at tamirgal.com] and we'll take it from there...
Cheers,
Tamir
-- modified at 10:55 Monday 30th October, 2006
|
|
|
|
|
Did you get this fixed...I am having a simular problem.
|
|
|
|
|