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

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 **

Hi,

Thanks for pointing this out.
Can you probably provide more information under which .Result can be called prior calling .Match method?
After checking my code I noticed that I always test if match was Success before calling Result method.

May be there is something I overlooked.

Thanks,
Oleg


New Post: SCP copy to a specific folder

$
0
0
Hi,

I think you using this incorrectly.
It seems that you trying to upload stream into the folder which is obviously impossible.
I would change this line:
client.Upload(filestream, "/dir/sdcard/filename.zip"); 
To point to specific file.

Hope it helps.

Thanks,
Oleg

New Post: OperationTimeout and ConnectionInfo.Timeout don't terminate the process

$
0
0
Hi,

I think there is a little misunderstanding about timeout parameter.
What it basically means is if there is no response from the server for lets say 30 sec, then throw an exception.
But if upload goes correctly and it keep uploading and server did not disconnect for example or no other unexpected error occurred on the server then timeout will not be hit.

Hope it explains a little more.

Thanks,
Oleg

New Post: Mono Support?

$
0
0
Thanks for the Response Oleg.

Is there a way to capture and display the standard error and standard output of the attempted ssh connection? I'm sure if I can see what the error really is I can craft a solutions.

My guess is the ssh session connection attempt is hanging at something like this:
$ ssh 192.168.170.209
The authenticity of host '192.168.170.209 (192.168.170.209)' can't be established.
RSA key fingerprint is 93:2e:4c:3f:d7:33:0f:43:54:1a:35:3e:50:02:06:a4.
Are you sure you want to continue connecting (yes/no)? 
But without a response back from the failed connection attempt I'm just shooting in the dark...

Nathan

New Post: Mono Support?

$
0
0
Hi Nathan,
Actually the message that you see its something that client displays, its not part of the protocol, to wait for response.
Did you try to debug it? Where does it hang? What line?
Also, did you try to connect to different server and you have the same behavior everywhere?

Thanks,
Oleg

Commented Issue: Add the XML documentation to the NuGet package [1477]

$
0
0
Please, can you add the generated xml documentation to the nuget package so we can get the intellisense help working.

Thanks
Comments: ** Comment from web user: eferreyra **

Have checked and its fine now, thanks.

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: JohRest **

Hi Oleg,

I was just checking the code while connecting to our squit http proxy. (3.0). During connection communication I noticed that there was a 403 coming back over the wire. So I found in Session.cs (copied from codeplex directly):

// Read response body if specified
if (string.IsNullOrEmpty(response) && contentLength > 0)
{
var contentBody = new byte[contentLength];
this.SocketRead(contentLength, ref contentBody);
}

if (statusCode == 200 && string.IsNullOrEmpty(response))
{
// Once all HTTP header information is read, exit
break;
}
else
{
var reasonPhrase = match.Result("${reasonPhrase}");
throw new ProxyException(string.Format("HTTP: Status code {0}, Reason \"{1}\"", statusCode, reasonPhrase));
}

In the last else branch you're trying to match

var reasonPhrase = match.Result("${reasonPhrase}");

on a response that by that time is empty and therefore I suggested the code change. At that point in time the method already "knows" that there's an error condition (!= 200) and thus the error description is clear and there (in my opinion) is no need to use regex to try to fiddle it out of the server response.

The method just has to translate the error code 403 into something readable to return it to the user. At the moment the user just receives a "A result cannot be called on a failed match" as exception, what is not the "real" exception and could confuse the caller (as it did when I first received that exception)

Kind regards

Johannes

New Post: SCP copy to a specific folder

$
0
0
Hi Oleg,

The fix in 22896 works for uploading a file, but doesn't work when uploading a directory:
using (var c = new ScpClient("host", "user", "password"))
{
    c.Connect();
    var di = new DirectoryInfo(@"c:\toupload");
    // FAILS - scp: error: unexpected filename: /var/wwwroot
    c.Upload(di, "/var/wwwroot"); 
    c.Disconnect();
}

Created 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;
}
}
}

Any suggestions?

New Post: Problem with uploading to Unix

$
0
0
When I try to use SCPClient to copy several big files (1 gb) from windows machine to unix machine, I have problem
First target file have same size , but others don't uppload full. They have less size then source files.
It's code
using (var sftp = new SftpClient(Host, Port, Login, Password))
        {
            List<string> movedFiles = new List<string>();
            try
            {

                string[] SourceFiles = Directory.GetFiles(SourceDirectory, this.SourceFileName + this.SourceFileFormat);
                {
                    foreach (string sourceFile in SourceFiles)
                    {
                        string resultTargetFile = TargetName;
                        if (String.IsNullOrEmpty(TargetFileName) || isMask)
                        {
                            resultTargetFile = Path.Combine(TargetDirectory, Path.GetFileName(sourceFile)).Replace(@"\", "/");
                        }
                        movedFiles.Add(resultTargetFile);
                        sftp.Connect();
                        using (var streamFile = File.OpenRead(sourceFile))
                        {
                            sftp.UploadFile(streamFile, resultTargetFile);
                        }
                        sftp.Disconnect();
                        cntOperation++;
                    }
                }

            }

            catch (ThreadAbortException)
            {
                if (sftp.IsConnected)
                {
                    foreach (string _movedFile in movedFiles)
                    {
                        if (sftp.Exists(_movedFile))
                            sftp.Delete(_movedFile);
                    }

                    sftp.Disconnect();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteMessage(MessageType.Error, ex.ToString());
            }
        }

Created Issue: SCP Won't Upload Directories [1511]

$
0
0
As per the discussion [here](http://sshnet.codeplex.com/discussions/284021), SCP doesn't currently work when uploading folders.

New Post: Problem with uploading to Unix

$
0
0
Well connect inside the loop... not really good thing. You should keep connection opened. You can call connect every time, because it will do nothing if connection is opened.

for the file size. You should check the real file size and not the file size on the HDD. Depend on the Sector size... each file will be bigger or smaller. So what is the difference between local and uploaded file?

New Post: ScpClient missing methods

$
0
0
well all this commands can be put into the base class...

New Post: Problem with uploading to Unix

$
0
0
At start I connected from outside a loop. But later I changed as it is now. I hoped that this will be solve the problem.

Now I have found problem and have solved it.

namespace Renci.SshNet
{
/// <summary>
/// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
/// </summary>
public partial class SftpClient : BaseClient
{
.
.
private void InternalUploadFile(Stream input, string path, Flags flags, SftpUploadAsyncResult asyncResult, Action<ulong> uploadCallback)
{
.
.
                {
                    expectedResponses++;
                }

                offset += (uint)bytesRead;

                bytesRead = input.Read(buffer, 0, buffer.Length);
            }
            else if (expectedResponses > 0)
            {
                //  Wait for expectedResponses to change
                lock (expectedResponsesLock)
                {
                    Monitor.Wait(expectedResponsesLock);
                }
            }
        } while (bytesRead > 0 || expectedResponses > 0);

        this._sftpSession.RequestClose(handle);
Problem occurs when network write\read speed is faster than disk write\read speed. Then the value of expectedResponses becomes equals to 0, and the file isn’t being uploaded completely.
I added new condition in method InternalUploadFile bytesRead > 0 ||

I waiting patch with this correction...

New Post: Problem with uploading to Unix

$
0
0
Hi,

I actually solved this problem already but it didst make it to release version yet.
You can also download latest source code where this fix is already available.

Thanks,
Oleg

New Post: ScpClient missing methods

$
0
0
Hi,

Yes, I agree but I just dont want to overcrowd class with method, since SFTP class for example will have a lot of methods to support SFTP and other commands for SCP, shell, command exaction will be simply lost, so I guess for now I just would keep it in separate classes.

Thanks,
Oleg

New Post: Problem with uploading to Unix

$
0
0
Hello, Oleg!

When will you plan upload new release?

New Post: Problem with uploading to Unix

$
0
0
Hi,

I usually wait for a while to have few more fixes in, also busy with another project right now so dont have much time for this one at a moment :(:(.

Thanks,
Oleg

New Post: How to synchronize Threads?

$
0
0
So I have a application which queues up files and spawns Tasks to handle the uploading on separate threads. When I try to use the sftpClient inside this thread I get an exception:

Object synchronization method was called from an unsynchronized block of code

This happens when the Connect() method is called.
How do I get the sftpClient in sync with it's parent thread?

New Post: Small File Upload Problem

$
0
0
Hello, Oleg!
Now I have same problem... File is really have uploaded but the process just hangs there.
Can I see your solve for testing?
Viewing all 2955 articles
Browse latest View live


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