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

Commented Unassigned: Sftp BeginUploadFile is not uploading [1629]

$
0
0
I'm trying to send file asynchronously using sftp client BeginUploadFile.
Either using stream or string path.

See 1.png and 2.png to see the IAsynResult of the callback function.

I'm using it with dotnet 3.5

```
private void SendXmlFile(XDocument xDocument)
{
var fileName = GenerateFileName();

using (var client = new SftpClient("127.0.0.1", 990, "user01", "us3r01"))
{
client.Connect();

var stream = CreateStream(xDocument);
client.BeginUploadFile(stream, fileName, UploadCompleted);

client.Disconnect();
}
}
```
Comments: ** Comment from web user: drieseng **

Works fine here.
Please provide a full code example that shows the issue.


Commented Unassigned: Bash problemusing ssh.net Library [1591]

$
0
0
Hi, here is my code
```
ssh.Connect();
var cmd = ssh.CreateCommand("ls -all");
var asynch = cmd.BeginExecute(delegate(IAsyncResult ar)
{
Console.WriteLine(cmd.Result);
}, null);

var cmd1 = ssh.RunCommand("bash /etc/motor.sh"); // Perform long running task
var asynch1 = cmd1.BeginExecute(delegate(IAsyncResult ar)
{
Console.WriteLine(cmd1.Result);
}, null);

while (!(asynch.IsCompleted && asynch1.IsCompleted))
{
Console.WriteLine("Waiting for commands to complete...");
Thread.Sleep(2000);
}
cmd1.EndExecute(asynch1);
cmd.EndExecute(asynch);
ssh.Disconnect();

Console.ReadLine();
```
The problem is that command "ls -all" works well but any bash command doesn't work..
Any suggestions ?

Thank you :)
Comments: ** Comment from web user: drieseng **

Works fine for me.
Can you explain what problem you exactly ran into ?

Commented Issue: High CPU Load when opening a shell session [1555]

$
0
0
When starting a shell session I observe a high CPU load (100% on one core).
I use the following code to connect:


MemoryStream input = new MemoryStream();
MemoryStream output = new MemoryStream();
MemoryStream extOutput = new MemoryStream();
shell = client.CreateShell(input, output, extOutput);
shell.Stopped += new EventHandler<EventArgs>(shell_Stopped);
shell.ErrorOccurred += new EventHandler<Renci.SshNet.Common.ExceptionEventArgs>(shell_ErrorOccurred);
shell.Start();

Thanks for the great library!

David
Comments: ** Comment from web user: drieseng **

Works fine for me.
Can you provide more details ?

Commented Unassigned: Change Directory Command and Upload, Download [1672]

$
0
0
If I use the "Change Directory" command, to set the current working directory, with the File Exists, Rename, or Delete file operations the commands honor the current working directory and find the file without issue.

However, when doing an file Upload or Download, I need to qualify the file name with the absolute path to the file because those two commands do not recognize the current working directory for some reason.

Is this intentional or is this an issue?

Regards,

Mark Gillen
Comments: ** Comment from web user: drieseng **

I'm unable to reproduce this issue.
What version of SSH.NET are you using ?
Can you share a full code example that should allow me to reproduce this issue ?

Edited Issue: SCP : Missing files when using DirectoryUpload [1382]

$
0
0
Hi,I have the following environment:- Win7 / 64- .NET 3.5- MPC-Target :OpenSSH_6.0p1, OpenSSL 1.0.0j 10 May 2012- SSH.NET commit 19813I want to upload a directory structure (recursive, depth = 2) from the PC to a MPC basedLinux remote system. The total amount of data is about 8MB with 23 files from55 bytes to 4MB.Calling mScp.Upload(new DirectoryInfo(localDir), remoteDir) does not result anyerror and the Uploading event shoes uploading all files. But after Upload() returnedThere are a random number of missing files on the target (between 1 and 5).It tried the same with a PC based Linux as target what resulted in the same behaviour(OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011). It seems theproblem is caused anywhere within SSH.NET.Does anyone have a solution?Extension:I tried to workaround by replacing Upload(new DirectoryInfo(...)) by several singlecalls of Upload(new FileInfo(...)). This worked but is too slow for my application.
Comments: ** Comment from web user: drieseng **

Reopened since issue is not fixed for Ulrich.

Edited Issue: Unobserved exception rethrown by finalizer thread [1298]

$
0
0
Hi, There is an unhandled System.AggregateException in a worker thread within SSH.NET version 18974 that causes the container application to crash. The exception should be caught and rethrown to the caller. This error occurs when the connection between the SHH client and server is flaky, i.e. it comes on and off. I added an AppDomain unhandled exception handler to log the exception. Here is the stack trace of the exception: ERROR: SubsystemSession.cs(128): Object reference not set to an instance of an object.ERROR: SubsystemSession.cs(169): Renci.SshNet.Sftp.SubsystemSession.Session_ErrorOccured(Object sender, ExceptionEventArgs e) failed.ERROR: System.EventHandler`1.Invoke(Object sender, TEventArgs e) failed.ERROR: Session.cs(1929): Renci.SshNet.Session.RaiseError(Exception exp) failed.ERROR: Session.cs(1592): Renci.SshNet.Session.MessageListener() failed.ERROR: Session.cs(522): Renci.SshNet.Session.b__14() failed.ERROR: System.Threading.Tasks.Task.InnerInvoke() failed.ERROR: System.Threading.Tasks.Task.Execute() failed.ERROR: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.ERROR: Application domain unhandled exception. I am not too familar with Tasks, but I suspect the error could be fixed by adding a catch block to the try block at Session.cs, line 520, and rethrow the exception. I am posting this while I am trying to fix the issue in case someone else can help. Thanks, Robert
Comments: ** Comment from web user: drieseng **

Reopened since there are multiple reports that this issue is not fixed.

Patch Declined: #15836

$
0
0

drieseng has declined patch #15836.

Comment:
I committed another (similar) fix for this issue.

Commented Issue: IsConnected returns true when sshd has closed connection or network is not available [1898]

$
0
0
Currently, The IsConnection property (on BaseClient) returns true even when:
*** the server has shut down the ssh connection

To reproduce:

1. Create a connection (eg using SftpClient)
2. Kill sshd process on server.
3. Inspect value of IsConnected property.

*** the network is no longer available

To reproduce:

1. Create a connection (eg using SftpClient)
2. Unplug network cable
3. Inspect value of IsConnected property.

I can reproduce this with ssh.net built from SVN/TFS.
Comments: ** Comment from web user: tudisco **

According to:
http://stackoverflow.com/questions/515458/how-can-i-check-whether-a-tcp-socket-is-disconnected-in-c

There is a way to tell. But I have no experience with this problem.

I keep getting the same exception as https://sshnet.codeplex.com/workitem/1581


Source code checked in, #34717

$
0
0
Sign the assemblies for .NET 3.5, .NET 4.0, Silverlight 4 and Silverlight 5.

Edited Feature: .Net 4 Binary Not Strongly Named [1802]

$
0
0
The .Net 4.0 binary is not strongly named
Comments: ** Comment from web user: drieseng **

In the next release, the assemblies for .NET 3.5, .NET 4.0, Silverlight 4 and Silverlight 5 will be signed.

Source code checked in, #34718

$
0
0
Added build script which by default: * cleans the build output * compiles the solution in Release configuration * creates a NuGet package containing our assembly for all supported target frameworks Added nuspec file, and updated it with information on new features, breaking changes and fixes. Removed generated NuGet package.

Source code checked in, #34719

$
0
0
Use the same assembly name across all supported target frameworks.

Source code checked in, #34720

$
0
0
Add build scripts and related artifacts to solution.

Created Unassigned: Message type 120 is not valid [1908]

$
0
0
Hello,

I got following error in the session connect.

"Message type 120 is not valid"

Renci.SshNet.dll!Renci.SshNet.Session.LoadMessage(byte[] data) Line 1539
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 884 + 0xb bytes
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1585 + 0x8 bytes
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 529 + 0x8 bytes
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3d(object o) Line 25 + 0xf bytes

Server is at sftp.wrightimg.com. Here is the server info obtained from WinSCP

Session protocol = SSH-2
SSH implementation = WeOnlyDo-wodFTPD 3.1.3.348
Encryption algorithm = aes
Compression = No
File transfer protocol = SFTP-4

I appreciate your help.

Thanks,
-Tony

Commented Unassigned: SCPClient hangs (downloading) when connections problem occurred [1895]

$
0
0
SCPClient hangs (downloading) when connections problem occurred on Version: 2013.4.7

Simple way of reproduction:
1. Remove scp (/var/bin/scp) from remote mashine.
2. Try to download some file from this mashine.
3. Downloading hungs...

I think, there is some problem with PipeStream interaction (PipeStream has no reaction on disconnect or other connection problems).

My Code
```
_scp = new Renci.SshNet.ScpClient(_host, _login, _password);
_scp.Connect();
_scp.Download(filename, file);
```

First hangs thread:
> Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read(byte[] buffer, int offset, int count) Line 181 + 0xb bytes C#
mscorlib.dll!System.IO.Stream.ReadByte() + 0x28 bytes
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadByte(System.IO.Stream stream) Line 367 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadString(System.IO.Stream stream) Line 384 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.InternalDownload(Renci.SshNet.Channels.ChannelSession channel, System.IO.Stream input, System.IO.FileSystemInfo fileSystemInfo) Line 217 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.Download(string filename, System.IO.FileInfo fileInfo) Line 132 + 0x14 bytes C#

```
Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read
...
while (!this.ReadAvailable(count))
Monitor.Wait(this._buffer); // (will hungs infinite due to disconnection state - no one will write in PipeStream)
```
Second hangs thread:
> System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) + 0xc6 bytes
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x20 bytes
Renci.SshNet.dll!Renci.SshNet.Session.SocketRead(int length, ref byte[] buffer) Line 115 + 0x34 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Read(int length) Line 1500 + 0xf bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 805 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1582 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 529 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3c(object o) Line 25 + 0xf bytes C#
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x2d bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5a bytes
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x147 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x2d bytes
[Native to Managed Transition]

```
partial void SocketRead(int length, ref byte[] buffer)
{
var offset = 0;
int receivedTotal = 0; // how many bytes is already received
do
{
try
{
var receivedBytes = this._socket.Receive(buffer, offset + receivedTotal, length - receivedTotal, SocketFlags.None); // hungs here
if (receivedBytes > 0)
```
------- output ----------------
SshNet.Logging Verbose: 1 : Initiating connect to '.............'.
SshNet.Logging Verbose: 1 : Server version '2.0' on 'OpenSSH_5.9p1 Debian-5ubuntu1.1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeRequest': 'SSH_MSG_KEX_DH_GEX_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeGroup': 'SSH_MSG_KEX_DH_GEX_GROUP'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeInit': 'SSH_MSG_KEX_DH_GEX_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeReply': 'SSH_MSG_KEX_DH_GEX_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
The thread '<No Name>' (0x724) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelWindowAdjustMessage': 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelExtendedDataMessage': 'SSH_MSG_CHANNEL_EXTENDED_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0x2254) has exited with code 0 (0x0).
The thread '<No Name>' (0x1474) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0xeb8) has exited with code 0 (0x0).
The thread '<No Name>' (0x27d8) has exited with code 0 (0x0).
The thread '<No Name>' (0x13f8) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
Comments: ** Comment from web user: Euan **

Same issue here. Just download a big bunch of files and pull out the ethernet cable.

There are multiple more places where SCP gets lost, this function in ScpClient.cs is good. Usually threads are sitting at var b.. but just looking at the function you can see it's a potential infinite loop.

```
private static int ReadByte(Stream stream)
{
var b = stream.ReadByte();

while (b < 0)
{
Thread.Sleep(100);
b = stream.ReadByte();
}

return b;
}
```
PipeStream.cs,
public override int Read(byte[] buffer, int offset, int count)
```
lock (this._buffer)
{
while (!this.ReadAvailable(count))
{
Monitor.Wait(this._buffer)) // stuck here forever
}
```

ScpClient.cs

private void InternalDownload(ChannelSession channel, Stream input, Stream output, string filename, long length)

Just goes round in circles receiving no data. I ended up putting a tick counter timeout in it to break out. It eventually gets the program free, but really messy...

```
private void InternalDownload(ChannelSession channel, Stream input, Stream output, string filename, long length)
{
var buffer = new byte[Math.Min(length, this.BufferSize)];
var needToRead = length;

bool aborted = false;
long prevRead = 0;
int prevTick = Environment.TickCount;
do
{
var read = input.Read(buffer, 0, (int)Math.Min(needToRead, this.BufferSize));

output.Write(buffer, 0, read);

this.RaiseDownloadingEvent(filename, length, length - needToRead);

needToRead -= read;

if (prevRead != needToRead)
{
prevTick = Environment.TickCount;
prevRead = needToRead;
}
else
{
if ((Environment.TickCount - prevTick) > 5000)
{
// found a stuck thread...
aborted = true;
break;
}
}

}
```
I'm still looking for the cause to exceptions not being raised properly.


Commented Unassigned: System.OutOfMemoryException when trying large files in sftp [1866]

$
0
0
Exception of type 'System.OutOfMemoryException' was thrown.
mscorlib
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Renci.SshNet.SftpClient.InternalDownloadFile(String path, Stream output, SftpDownloadAsyncResult asyncResult, Action`1 downloadCallback)

-------
Multiple files of 400MB or 1GB files.
The entire file is in the stream object that could be the problem.
--------
Comments: ** Comment from web user: chenthil_it **

thanks for the reply.
But the sftpfile stream is very slow it took 1hr 15 mins for 400mb file. I tried changing the buffer size but no success. Is there any transfer limit in sftpfilestream.

Commented Unassigned: Message type 120 is not valid [1908]

$
0
0
Hello,

I got following error in the session connect.

"Message type 120 is not valid"

Renci.SshNet.dll!Renci.SshNet.Session.LoadMessage(byte[] data) Line 1539
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 884 + 0xb bytes
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1585 + 0x8 bytes
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 529 + 0x8 bytes
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3d(object o) Line 25 + 0xf bytes

Server is at sftp.wrightimg.com. Here is the server info obtained from WinSCP

Session protocol = SSH-2
SSH implementation = WeOnlyDo-wodFTPD 3.1.3.348
Encryption algorithm = aes
Compression = No
File transfer protocol = SFTP-4

I appreciate your help.

Thanks,
-Tony
Comments: ** Comment from web user: tonychan **

I followed the code for handling SSH_MSG_USERAUTH_BANNER and mimic one for message type 120. Then, I realize the length=this.ReadUInt32() in ReadString() is 2,623,693,920 which is very big. Since I am unfamiliar with SSH protocol, I am stuck.

Here is the order of messages received.
20 - SSH_MSG_KEXINIT
31 - SSH_MSG_KEXDH_REPLY
21 - SSH_MSG_NEWKEYS
120 - (Invalid Message Type)

Reviewed: 2013.4.7 (Mar 03, 2014)

$
0
0
Rated 4 Stars (out of 5) - Using it for a almost an year no issues with sftp. Facing performance issue with large files but i think will be able to figure it out a way to fix it.

New Post: Run command unblocking

$
0
0
Thanks for your response it helped me solve my issue.

New Post: Executing grep command

$
0
0
I am using the ssh.net library and I am trying to run the following command:
string theCommand=grep <stringToLookFor> <filePathAndName>
client.RunCommand(theCommand);

The process hangs.

Then I tried using asynch:
SshCommand cmd=client.CreateCommand("grep "+stringInFile+" " + directory+fileName);
var asynch=cmd.BeginExecute();
while (!asynch.IsCompleted)
        {
           System.Threading.Thread.Sleep(100);

        }
        cmd.EndExecute(asynch);
And it does not return neither.

Any ideas on how I can run this grep command?
Thanks.
Viewing all 2955 articles
Browse latest View live


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