Quantcast
Channel: SSH.NET Library
Viewing all 2955 articles
Browse latest View live

Patch Applied: #13964


Commented Issue: Invalid handling of http proxy server response [1509]

$
0
0
Hi,

I did find a problem when testing the assembly with our squid 3.0 proxy. I receive the message, that Result cannot be called on a failed match. Therefore I've extended the code in Session.cs a little bit:

if (statusCode == 200 && string.IsNullOrEmpty(response))
{
// Once all HTTP header information is read, exit
break;
}
else
{
string reasonPhrase = string.Empty;

try
{
if (match.Success)
reasonPhrase = match.Result("${reasonPhrase}");
}
catch (Exception ex)
{
reasonPhrase = string.Empty;
}

Now the following line

throw new ProxyException(string.Format("HTTP: Status code {0}, Reason \"{1}\"", statusCode, reasonPhrase));

Does at least return the error code (not yet the fault reason; in this case ERR_ACCESS_DENIED)

In fact the code received a 403 status code from the proxy:

SshNet.Logging Verbose: 1 : Initiating connect to 'yyy.xxx.zzz.ww:22'.

HTTP/1.0 403 Forbidden
Server: squid/3.0.STABLE16-RC1
Mime-Version: 1.0
Date: Wed, 13 Feb 2013 14:15:06 GMT
Content-Type: text/html
Content-Length: 1008
Expires: Wed, 13 Feb 2013 14:15:06 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from app-proxy-3.xxxx.xxx
Via: 1.0 app-proxy-3.xxxx.xxx (squid/3.0.STABLE16-RC1)
Proxy-Connection: close

The thread 0xa2c has exited with code 0 (0x0).

Kind regards

Johannes
Comments: ** Comment from web user: olegkap **

I applied this fix in 23335 commit, with some minor modification, I did it actually a while ago but forgot to commit it so can you please take a look and see if it works?

Thanks,
Oleg

Source code checked in, #23336

$
0
0
Lock _encoding in ShellStream when GetString operation is performed

Source code checked in, #23337

$
0
0
Lock _incoming object where performing Enqueue Rollback previouse commit

Commented Issue: ArgumentException in Expect [1510]

$
0
0
While Unit Testing my solution using SSH.NET I run into some problem.
Sometimes I get error from SSH.NET during test (it is weird, because it happen once 5-6 runs)

Exception: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.Queue`1.ToArray()
at Renci.SshNet.ShellStream.Expect(Regex regex, TimeSpan timeout)

my code looks like:

string buffer = string.Empty;
using (ShellStream shellStream = _sshClient.CreateShellStream("xterm0", 80, 24, 800, 600, 1024))
{
try
{
shellStream.ErrorOccurred += ErrorHandling;
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
shellStream.WriteLine(cmd);
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
}
finally
{
if (shellStream != null)
{
shellStream.ErrorOccurred -= ErrorHandling;
}
}
}

I looked into source code, it look like problem is in ShellStram Expect Method (line 273)
it is:
if (this._incoming.Count > 0)
text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);

it should be:
if (this._incoming.Count > 0)
{
var array = this._incoming.ToArray();
text = this._encoding.GetString(array, 0, array.Length);
}
Comments: ** Comment from web user: olegkap **

Hi guys,
Thanks for this feedback and sorry for late reply to this one.

I guess I missed locking _incoming in Channel_DataReceived method, thanks blakeja.

I guess I overlooked it.

I just committed your fix so please let me know if it works which I think should solve this issue as this is the only place where I didn't lock _incoming object it seems.

Thanks,
Oleg

New Post: Pageant integration?

$
0
0
Hi,

I have somebody submitted it as a patch to be included in the library but unfortunately I could not include it since this solution is application specific.
If you interested you can download this patch here and see if it works for you.

Also, if you like and can create of this some klind of add on solution I could post it here as a seperate file that people can add or use if they would like pageant support.

Hope it helps.

Thanks,
Oleg

Commented Issue: Trouble with Multiple Connections [1517]

$
0
0
Thanks for this great resource.

I'm having issues with connections dropping when I instantiate more than a few (4 or more) SshClients in the same application. If I run separate instances of the same application (each with 1 SshClient), my problems go away. Can you think of any possible causes (maybe static methods with locks that block use from multiple instances of the class)?
Comments: ** Comment from web user: olegkap **

Hi,

Well, I do have a lock which will enforce only 3 connection at a time to allow authenticate but once it is authenticated it should allow more connections to be established.

Does this behavior the same when you try to connect to different host?
Sometimes server will enforce different policies and will drop connection if policy is violated.

Can you try with different server and let me know what happens?

Thanks,
Oleg

New Post: will these scpclient settings help out with timeout issues on connection attempt?

$
0
0
Yes,
Increasing this timeout should allow server more time to respond and for client to receive reply.

Thanks,
Oleg

New Post: Installation of SSH Net Library

$
0
0
Hi,

Sorry I cant really help you with powershell.

You might want to check this.

Hope it will help.

Thanks,
Oleg

New Post: Connected to IPv6 rather than IPv4

$
0
0
Yes,
I have it on my list but will take a little time since I dont have much free time recently and to change that I want to maintain backward compatibility with string address as well.

I will try to address this as soon as possible3.

Thanks,
Oleg

Commented Issue: Trouble with Multiple Connections [1517]

$
0
0
Thanks for this great resource.

I'm having issues with connections dropping when I instantiate more than a few (4 or more) SshClients in the same application. If I run separate instances of the same application (each with 1 SshClient), my problems go away. Can you think of any possible causes (maybe static methods with locks that block use from multiple instances of the class)?
Comments: ** Comment from web user: bgulrich **

Yes, each is a different host - I'm connecting to about 10 at a time then using SshShellStream to write commands and read responses from each simultaneously.

Created Issue: Issue disconnecting. raising sshconnectionException Client not connected. [1519]

$
0
0
After making a sftp connection, using the function ListDirectory(path), checking IsConnected and if so calling Disconnect() will raise an exception.

New Post: Blob Support

$
0
0
Hi,

Currently there is no plans to do that since this is something not defined by SFTP protocol and wildcards could be different and platform specific and implemented differently by clients.


So I guess currently the only choice probably is to read all directory and then apply regex on this. Just something to keep in mind that directory could be very big and contain thousand of files.

If you like you can open it as feature request so I could see if there is enough interest in it as well as possible usage and implementation scenarios.

Thanks,
Oleg

Commented Issue: Partial Reads from Stream assume end? [1516]

$
0
0
Hi, thanks for all your work on this library.

We are using an implementation of a ProducerConsumerStream from [here](http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=852) as our means of feeding data into the ftp transfer. This is essentially a buffered stream that stalls the feeder, whilst the reader catches up - otherwise the stream could fill quickly and hog memory on our server whilst a poor ftp connection stalls the reader.

This presents a problem in that the SftpClient implementation assumes that a partial stream is the final block - whereas in our case this could occur at any point in the lifetime of the transfer as the buffered stream could be smaller than the buffer it is being read into. Worse still, should the feeder only populate half of the buffer on the first read, the client will complete the transfer.

I've tried to understand the code in the InternalUploadFile but I'm struglling to find the exit point. What will also happen is the resize of the buffer for the assumed last block - means that even if it did continue it's iterations the buffer is reduced to the smaller size. If the partial read is only 1 byte, then the buffer is reduced to 1 byte each read!!! Arggh!

Can you provide me with guidance on how the InternalUploadFile exit point is reached from the partial read...? Thanks
Comments: ** Comment from web user: olegkap **

Hi,
If I remember correctly when I was doing test I also tested against scenario where file is smaller than a buffer but I might be wrong.

Can you post a code example that I can use to recreate the problem?

As far as InternalUploadFile method, it exits only when all responses was received to request sent by do..while loop and all bytes are read from input stream.

Hope it helps.

Thanks,
Oleg

New Post: Failing to Authenticate on SSH_MSG_USERAUTH_PASSWD_CHANGEREQ

$
0
0
Hi,

Sorry for late response.
The reason SSH_MSG_USERAUTH_PASSWD_CHANGEREQ needs to be sent its because it detects that username password needs to be changed.
I am no sure how and why FileZilla works, may be internally it changes password to itself again or uses some other trick, o might have a bug.
See if you can handle PasswordExpired event. This event is raised when you need to provide a new password.

Here is an example of how you would do it:
           var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
            var encoding = new Renci.SshNet.Common.ASCIIEncoding();
            connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e)
            {
                e.NewPassword = encoding.GetBytes("123456");
            };

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();

                client.Disconnect();
            }
Hope it helps.

Thanks,
Oleg

New Post: Multiple commands in sequence (C#)

$
0
0
teejmonster: I can verify this as well.

I tested with a lot of different Cisco devices. All of the ones running Native IOS drop the connection after the first command. Only newer NX-OS and IOS-XE devices (which are based on Linux) will properly keep the connection open.

The only real workaround is to code everything to use a shell connection instead.

Commented Issue: ArgumentException in Expect [1510]

$
0
0
While Unit Testing my solution using SSH.NET I run into some problem.
Sometimes I get error from SSH.NET during test (it is weird, because it happen once 5-6 runs)

Exception: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.Queue`1.ToArray()
at Renci.SshNet.ShellStream.Expect(Regex regex, TimeSpan timeout)

my code looks like:

string buffer = string.Empty;
using (ShellStream shellStream = _sshClient.CreateShellStream("xterm0", 80, 24, 800, 600, 1024))
{
try
{
shellStream.ErrorOccurred += ErrorHandling;
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
shellStream.WriteLine(cmd);
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
}
finally
{
if (shellStream != null)
{
shellStream.ErrorOccurred -= ErrorHandling;
}
}
}

I looked into source code, it look like problem is in ShellStram Expect Method (line 273)
it is:
if (this._incoming.Count > 0)
text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);

it should be:
if (this._incoming.Count > 0)
{
var array = this._incoming.ToArray();
text = this._encoding.GetString(array, 0, array.Length);
}
Comments: ** Comment from web user: blakeja **

I haven't seen this exception again, I believe this fixed issue.

Closed Issue: ArgumentException in Expect [1510]

$
0
0
While Unit Testing my solution using SSH.NET I run into some problem.
Sometimes I get error from SSH.NET during test (it is weird, because it happen once 5-6 runs)

Exception: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.Queue`1.ToArray()
at Renci.SshNet.ShellStream.Expect(Regex regex, TimeSpan timeout)

my code looks like:

string buffer = string.Empty;
using (ShellStream shellStream = _sshClient.CreateShellStream("xterm0", 80, 24, 800, 600, 1024))
{
try
{
shellStream.ErrorOccurred += ErrorHandling;
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
shellStream.WriteLine(cmd);
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
}
finally
{
if (shellStream != null)
{
shellStream.ErrorOccurred -= ErrorHandling;
}
}
}

I looked into source code, it look like problem is in ShellStram Expect Method (line 273)
it is:
if (this._incoming.Count > 0)
text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);

it should be:
if (this._incoming.Count > 0)
{
var array = this._incoming.ToArray();
text = this._encoding.GetString(array, 0, array.Length);
}
Comments: Fixed in 23337

Commented Issue: ArgumentException in Expect [1510]

$
0
0
While Unit Testing my solution using SSH.NET I run into some problem.
Sometimes I get error from SSH.NET during test (it is weird, because it happen once 5-6 runs)

Exception: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.Queue`1.ToArray()
at Renci.SshNet.ShellStream.Expect(Regex regex, TimeSpan timeout)

my code looks like:

string buffer = string.Empty;
using (ShellStream shellStream = _sshClient.CreateShellStream("xterm0", 80, 24, 800, 600, 1024))
{
try
{
shellStream.ErrorOccurred += ErrorHandling;
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
shellStream.WriteLine(cmd);
buffer = shellStream.Expect(">");
if (buffer == null)
{
throw new InvalidDataException("timeout waiting for command prompt");
}
}
finally
{
if (shellStream != null)
{
shellStream.ErrorOccurred -= ErrorHandling;
}
}
}

I looked into source code, it look like problem is in ShellStram Expect Method (line 273)
it is:
if (this._incoming.Count > 0)
text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);

it should be:
if (this._incoming.Count > 0)
{
var array = this._incoming.ToArray();
text = this._encoding.GetString(array, 0, array.Length);
}
Comments: ** Comment from web user: olegkap **

Thanks for checking that I am closing this issue now.

Thanks,
Oleg

Created Issue: Orphaned threads when port forwarding [1522]

$
0
0
I'm not sure if this is the same issue as [here](http://sshnet.codeplex.com/workitem/1436).

In the situation where a port forward has been established and actively used, therefore a listener thread has been created, if the network is disconnected (by pulling out the cable) and reconnected sometime later then the internal thread will remain there even after everything else has been disposed properly. This causes problems, especially when trying to exit the application since it will hang.

With a fair amount of Console.WriteLineing it was established that the internal listener thread, consisting mostly of the Bind function in ChannelDirectTcpip, eventually exits its main loop correctly but then stalls at this point forever (well at least until a kill -9 is issued):

```
System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof });
```

I do not know much about the inner workings of SSH.NET and therefore do not know the best solution to the problem, but a workaround that seems to do the job for us is to simply allow that wait to timeout:

```
System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof }, 5000);
```

After that, the inner thread exits properly and no more hangs on exit.
Viewing all 2955 articles
Browse latest View live


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