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

New Post: Error accessing SFTP site from server, yet works from PC

$
0
0
Hi,
I have an issue trying to connect to a SFTP server, where I get the error:=
"Error! No suitable authentication method found to complete authentication."
The weird thing is that when I deploy my application (it is a windows service) to my local PC it works perfectly, but deployed to a server, I get the above error.
Any thoughts??? Code below....
Thanks
Paul

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.SshNet;
using System.IO;

namespace TestSFTP
{
class Program
{
    static void Main(string[] args)
    {
        Stream s = File.OpenRead(@"\\rhea\itshared\Software Support\Landscape\MID\Identity");
        PrivateKeyFile p3 = new PrivateKeyFile(s, "Canopius99");
        PrivateKeyAuthenticationMethod pram = new PrivateKeyAuthenticationMethod("cmid0038cano", p3);
        ConnectionInfo c = new ConnectionInfo("194.60.191.31", 22, "cmid0038cano", pram);
        SftpClient client = new SftpClient(c);
        client.Connect();
        client.ChangeDirectory("from_xpn");  // change to where the files are on the target server
        var listdirectory = client.ListDirectory(client.WorkingDirectory,null);
        foreach (var fi in listdirectory) // Check to see if there us a file to process.....
        {
            System.Console.WriteLine(fi.FullName);
        }
        client.Disconnect();
    }
}
}

New Post: CreateShell

New Post: Mounting a network drive using SSH

$
0
0
Hi

I want to use a secure samba port to mount a network drive.

I understand how to create the connection, but am unsure on how to tell if it is doing what I want it to, would I be better off redirecting the port, or can I simple create a secure connection and connect to a network drive using net.exe or something similar.

Many thanks in advance.

New Post: sftp behind proxy unable to connect

$
0
0
ok,

I've got a bit more information, the sockets are getting blanks and the connect method is stuck in this loop:

System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::BeginReceive() -> OverlappedAsyncResult#15796147
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::EndReceive(OverlappedAsyncResult#15796147)
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::EndReceive() -> Int32#0
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::BeginReceive()
System.Net.Sockets Verbose: 0 : [7256] Data from Socket#51791499::PostCompletion
System.Net.Sockets Verbose: 0 : [7256] 00000000 : :
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::BeginReceive() -> OverlappedAsyncResult#39737976
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::EndReceive(OverlappedAsyncResult#39737976)
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::EndReceive() -> Int32#0
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::BeginReceive()
System.Net.Sockets Verbose: 0 : [7256] Data from Socket#51791499::PostCompletion
System.Net.Sockets Verbose: 0 : [7256] 00000000 : :
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::BeginReceive() -> OverlappedAsyncResult#43378475
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::EndReceive(OverlappedAsyncResult#43378475)
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::EndReceive() -> Int32#0
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::BeginReceive()
System.Net.Sockets Verbose: 0 : [7256] Data from Socket#51791499::PostCompletion
System.Net.Sockets Verbose: 0 : [7256] 00000000 : :
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::BeginReceive() -> OverlappedAsyncResult#5874319
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::EndReceive(OverlappedAsyncResult#5874319)
System.Net.Sockets Verbose: 0 : [6392] Exiting Socket#51791499::EndReceive() -> Int32#0
System.Net.Sockets Verbose: 0 : [6392] Socket#51791499::BeginReceive()
System.Net.Sockets Verbose: 0 : [7256] Data from Socket#51791499::PostCompletion
System.Net.Sockets Verbose: 0 : [7256] 00000000 :

Any help would be massively appreciated

New Post: SFTPClient (2013.4.7 library) and SSH1

$
0
0
Hi Guys,

I was trying to connect to a remote server which was failing silently. I can connect to server via WinSCP as it fallsback to SSH1, is there a way we can specify SSH1 in the connectionInfo class or SFTPClient? I am failing to find a reference.

Any help will be appreciated.

thanks,

New Post: Running nuhup command using SSH.NET

$
0
0
What is wrong with this code?
using (var client = new SshClient("host", "user", "password"))
                {
                    client.Connect();

                   // var result = client.RunCommand(<ValidCommand>);  // command executing and doing fine
                    var result2 = client.RunCommand("nohup <ValidCommand> &"); // nothing happend - error and result are empty. On linux server nohup.out doesn't appear

                    client.Disconnect();

                }
How to run nohup command? What is wrong with this code?

Thanks in advance for your answers.

Commented Issue: SFTP: Uploading Files to the FTP Server has Inconsistent Behavior [1550]

$
0
0
__Method Name:__ UploadFile()

__Issue:__ Files Uploaded to FTP Server has Inconsistent Behavior

I am trying to upload the file from local path to the ftp server, there is no exceptions in the uploadFile() method , but most of the times files were not uploaded and few times empty file was being uploaded.

Here is my code for uploading a file to the server:

using (var sftp = new SftpClient(sftpHost, user, password))
{
sftp.Connect();
string FilePath = "D:\\CurrentTask\\in\\new.txt";
string remoteFileName = "/folderName/filename.txt";

Stream fs = File.OpenRead(FilePath);
sftp.UploadFile(fs, remoteFileName);

sftp.Disconnect();
}

Could you help me to resolve this issue?

Thanks in Advance.
Comments: ** Comment from web user: tigertall **

the same for me

New Post: Scp Upload, remote file quotes...

$
0
0
Hi All,

Trying to use ScpClient,

filename - stringing full file path/name
               ScpClient scpClient = new ScpClient(host, username, password);
               scpClient.Connect();
               scpClient.Upload(File.OpenRead(fileName), Path.GetFileName(fileName));
               scpClient.Disconnect();
and got "filename" (with quotes) on remote device

trying ScpClient.Upload(FileInfo, String) method - uploaded file size not equals original and have quotes too.

device - RouterOS, (http://mikrotik.com)

New Post: Error accessing SFTP site from server, yet works from PC

$
0
0
My first thought is that the server cannot read the private key file.

New Post: NetConfClient talking to NXOS XMLAGENT hangs

$
0
0
When creating an object using Renci.SshNet.NetConfClient it appears that a the client "Hello" does not complete. I think it is related to a missing EOL (CRLF)

when I use a SSH client such as putty a hangs like this ocurs when the hello string is terminated with a ]]>]] and CRLF. Looking at the code I'm pretty sure the hello being sent (ClientCapabilities
  • ]]>]] ) .
code example and ouput:

[void][reflection.assembly]::LoadFrom( (Resolve-Path "$pwd\bin\Renci.SshNet.dll") )

$mynetconf = New-Object Renci.SshNet.NetConfClient("1.2.4.4", "admin", "Password")
$mynetconf.Connect()
$mydata = $mynetconf.SendReceiveRpc($test1)


write-host $mydata.InnerText
applicationoperation-failederrorcurrent session has not received hello

I'm pretty sure the netconf client is sending the data.

below are are the contents of the server/client capabilities data.

PS C:\Scripts\bin> $mynetconf.ServerCapabilities.InnerText
urn:ietf:params:xml:ns:netconf:base:1.029764
PS C:\Scripts\bin> $mynetconf.ClientCapabilities

xml hello

version="1.0" encoding="UTF-8" hello


PS C:\Scripts\bin> $mynetconf.ClientCapabilities.InnerText
urn:ietf:params:netconf:base:1.0

New Post: Receiving no result, no response from remote linux server

$
0
0
Hi all,
I'm trying to execute few commands on remote linux server through SSH.NET (SshClient). I'm getting connected successfully, but when I gave new command suppose (cd mydir) I don't receive any error message, exception or any result, even no info from SshCommand.OutputStream.
Please help me... how I can get my work done..

private void txtQuery_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            txtResult.Clear();

            var cmd = client.CreateCommand(txtQuery.Text.Trim());
            var asynch = cmd.BeginExecute();
            var reader = new StreamReader(cmd.OutputStream);
            while (!asynch.IsCompleted)
            {
                var result = reader.ReadToEnd();
                if (String.IsNullOrEmpty(result))
                    continue;
                else
                {
                    txtResult.AppendText(result + "\r\n");
                }
            }
            string cmdResult = cmd.EndExecute(asynch);
            if (!String.IsNullOrEmpty(cmdResult))
            {
                txtResult.AppendText("\r\n\r\n\r\n" + cmdResult);
            }



        }
    }

Suppose I'm connecting by given host, name and password, the next thing what i'm doing as testing .......... I have a TextBox named "txtQuery" .... I write a command in the text box and wanted to see results (error, exceptions or whats so ever is that) to a new TextBox named "txtResult"........ I give many commands but received no ERROR, EXCEPTION or other info.

New Post: When Listing files using ListDirectory is there a way to not include child directories?

$
0
0
I need to list the files in the current directory without getting the child directories. Is there a way to do this?
filePath = "."
For Each f As Renci.SshNet.Sftp.SftpFile In ssh2.ListDirectory(filePath)
          fileList.Add(f.Name)
Next

New Post: When will an updated nuGet package become available?

$
0
0
Let me start by saying thanks for the wonderful open source library! It's been a great resource for us.

I'd like to ask when an updated nuGet package can be expected. We've experienced a Null Reference exception in the 2013.4.7 version that appears to be resolved with one of the more recent checkins (I believe it's 28765). While we were able to pull the source and build our own binary that resolved the issue, we had to undo our automatic nuGet package pulling in favor of our locally built binary. We'd of course much rather stick with the nuGet package if possible.

Any information is greatly appreciated. Thanks!

Commented Unassigned: Problems with IPSwitch MoveIt SSH server [1785]

$
0
0
Has anyone had problems when using the code with IPSwitch MoveIt ?

I can connect OK, list files, rename, upload & download. But when I try to delete a file I get "permission denied".
Although if I connect to the MoveIt server with Filezilla client I can delete the file, so it's not a permissions issue.
And my code is fine because I can delete files no problem from UNIX & LINUX servers.
It has a similar problem when I try to overwrite an existing file.

Any help would be appreciated.

Cheers

Phil
Comments: ** Comment from web user: IdidWhat **


I have the same problem trying to overwrite an existing file. Did you ever solve this?

Thanks,
Gary

Reviewed: 2013.4.7 (Dec 12, 2013)

$
0
0
Rated 1 Stars (out of 5) - Can you please provide a zipped version of the compiled library. it is blocked otherwise by most big corps.

Created Unassigned: In some error cases, an unhandled exception might be thrown from a worker thread (uncatchable) [1840]

$
0
0
There is a race condition that can cause an unhandled exception to be thrown. Take a look at the following code:

```C#
try
{
// "server" needs to be changed to a real SSH server
// The credentials do not need to be valid
using (SftpClient client = new SftpClient("sftp.autoloop.us", "user", "password"))
{
client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e)
{
e.CanTrust = false;
};

client.Connect(); // <-- Exception from untrusted host key bubbles up here
} // <-- End of using block causes client.Dispose() to be called, causing an unhandled exception in another thread
}
catch (Exception ex)
{
// This code isn't executed because of the unhandled exception from another thread
Console.WriteLine("There was an error connecting to the server: {0}", ex.Message);
}
```

On my machine, this results in the following exception almost every time:

```
Renci.SshNet.Common.SshConnectionException was unhandled
HResult=-2146233088
Message=Client not connected.
Source=Renci.SshNet
StackTrace:
at Renci.SshNet.Session.SendMessage(Message message) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 658
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 893
at Renci.SshNet.Session.RaiseError(Exception exp) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 1914
at Renci.SshNet.Session.MessageListener() in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 1594
at Renci.SshNet.Session.<Connect>b__4() in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 529
at Renci.SshNet.Session.<>c__DisplayClass3d.<ExecuteThread>b__3c(Object o) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.NET40.cs:line 25
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
InnerException:

```

The problem is that `Session` is getting disposed (by the `using` statement) prior to `Session.SendDisconnect` being called from another thread while the client attempts to clean up from the exception thrown by the lack of trust in the host key (or a bad set of user credentials, and probably other conditions).

Patch Uploaded: #15568

$
0
0

dcormier has uploaded a patch.

Description:
This patch fixes a race condition that may cause an unhandled exception when Session.RaiseError is called from within Session.MessageListener(). This exception is on a worker thread, so cannot be caught by the caller of the client. The solution is to not let the main thread throw its exception until the worker thread has finished cleaning up.

Created Unassigned: ForwardedPortDynamic unhandled exception if client terminates socket [1844]

$
0
0
In my experimenting, it wasn't uncommon for a browser to initiate a connection with the SOCKS proxy hosted by SSH.NET, then abort the connection before the response came back.

This resulted in a SocketException on line 24 of ChannelDirectTcpip.NET35.cs (which calls `this._socket.Send`, complaining that the socket wasn't open.

Wrapping the call to `this.InternalSocketSend(data)` on line 159 of ChannelDirectTcpip.cs in a try/catch (and ignoring SocketExceptions) provided a workaround, but I don't know if there's a better solution.

Thanks!

Created Unassigned: SftpClient ctor throws exception when hostname has _ character [1845]

$
0
0
The constructor for SftpClient and SshClient class throws an ArgumentException when the hostname has an underscrore character '_' . Using disassembly I can find the issue is the regex _rehost in Extensions.cs

This regex should be fixed as _ is valid hostname.

Commented Unassigned: In some error cases, an unhandled exception might be thrown from a worker thread (uncatchable) [1840]

$
0
0
There is a race condition that can cause an unhandled exception to be thrown. Take a look at the following code:

```C#
try
{
// "server" needs to be changed to a real SSH server
// The credentials do not need to be valid
using (SftpClient client = new SftpClient("sftp.autoloop.us", "user", "password"))
{
client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e)
{
e.CanTrust = false;
};

client.Connect(); // <-- Exception from untrusted host key bubbles up here
} // <-- End of using block causes client.Dispose() to be called, causing an unhandled exception in another thread
}
catch (Exception ex)
{
// This code isn't executed because of the unhandled exception from another thread
Console.WriteLine("There was an error connecting to the server: {0}", ex.Message);
}
```

On my machine, this results in the following exception almost every time:

```
Renci.SshNet.Common.SshConnectionException was unhandled
HResult=-2146233088
Message=Client not connected.
Source=Renci.SshNet
StackTrace:
at Renci.SshNet.Session.SendMessage(Message message) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 658
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 893
at Renci.SshNet.Session.RaiseError(Exception exp) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 1914
at Renci.SshNet.Session.MessageListener() in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 1594
at Renci.SshNet.Session.<Connect>b__4() in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.cs:line 529
at Renci.SshNet.Session.<>c__DisplayClass3d.<ExecuteThread>b__3c(Object o) in c:\temp\Test\Third Party\sshnet-31793\Renci.SshClient\Renci.SshNet\Session.NET40.cs:line 25
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
InnerException:

```

The problem is that `Session` is getting disposed (by the `using` statement) prior to `Session.SendDisconnect` being called from another thread while the client attempts to clean up from the exception thrown by the lack of trust in the host key (or a bad set of user credentials, and probably other conditions).
Comments: ** Comment from web user: dcormier **

I've submitted a patch (ID 15568) to address this.

Viewing all 2955 articles
Browse latest View live


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