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

New Post: Hanging indefinitely while trying to write to the stream

$
0
0
I didn't want to mess with the source code of the SSH library in case it caused some further error.

My stopgap solution was to encapsulate any call that might throw the exception that triggers the dispose inside it's own thread. If the thread doesn't complete within a specified time, I interrupt it. Less than ideal, but it works for the moment.

New Post: Low performance (Upload time comparing)

$
0
0
Hi, wonder if you managed to find this issue.

I'm using sshnet to provide port forwarding for mysql backend of client application, and that does work great.

Recently, we decided to do some more processing on server side, and as mysql is not capable of dealing with more complicated stored procedures I have decided to try scripts.

Unfortunately on existing mysql connection I can process nearly 300 queries per second, while same calculation using .RunCommand() or async .BeginExecute() does avg 20 calls per sec. it is also very unstable, in a way that it does not keep one rate, rather sinusoid between 10-200.

For test I used command:
mysql: SELECT {0} * 2
script: "echo -n $(({0} * 2))"

Is there any way make sshnet process script calls faster?

Thanks
J

Commented Unassigned: Permission Denied while doing an SFTP with Public Private Key combination [2615]

$
0
0
Hi,

We have an intermittent issue where the SFTP fails when we use the Public Private key mode of authentication.

Below is the code snippet which is used to connect to SFTP.

using(Renci.SshNet.SftpClient sftpClient = new Renci.SshNet.SftpClient( AppConfigHelper.Axway_FTPServer,
AppConfigHelper.Axway_FTPUserName,
new Renci.SshNet.PrivateKeyFile[] {
new Renci.SshNet.PrivateKeyFile(File.OpenRead(AppConfigHelper.PrivateKeyFilePath), AppConfigHelper.Passphrase)
}))

{
try
{
sftpClient.Connect();
sftpClient.ChangeDirectory(AppConfigHelper.Axway_UploadFolderName);
using (FileStream fs = new FileStream(fileNameWithPath, FileMode.Open))
{
sftpClient.UploadFile(fs, completeFileName);
LogHelper.LogInfo(string.Format("File {0} uploaded successfully",completeFileName));
}
}
catch (Exception ex)
{
LogHelper.LogInfo(string.Format("File {0} upload failed", completeFileName));
}
finally
{
if (sftpClient != null)
{
if (sftpClient.IsConnected)
sftpClient.Disconnect();

sftpClient.Dispose();
}
}
}


The issue is very intermittent (happens only once in maybe 50 times or 100 times) and doesn't happen at all when we use the password mode of authentication (So we want to know what is wrong with the Public Private key mode of authentication).

For some reason it is not able to connect to the SFTP server and throws the error "Permission Denied".

When I check for sftpClient.IsConnected, sftpClient.ConnectionInfo.IsAuthenticated, both are false when the SFTP fails.

Kindly let us know if there is a suggestion/solution/work around for this problem.

Thanks & Regards,
Sindoor
Sindhoor.bj@gmail.com
Comments: ** Comment from web user: sindhoor_bj **

Hi Sandesh,

I still didn't get a resolution for this, but in the meantime I have set a retry on failure and it always works on the second time,

Thanks & Regards,
Sindhoor

New Post: How to send results of client.RunCommand to a listbox WinForms C#

$
0
0
Hi There

I am trying to use SSH.Net in a WinForms app, however I am having issues trying to ouput the result of a command to a listbox. I can connect fine to the server.
Debugging the line with string output I get "output = "Renci.SshNet.SshCommand" The value of command is correct with ls -la
private void btnExecute_Click(object sender, EventArgs e)
        {
            var connectionInfo = new PasswordConnectionInfo(host, port, username, password);
            lblStatus.Text = "Trying SSH connection...";
            //connectionInfo.Timeout = TimeSpan.FromSeconds(10);
            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                if (client.IsConnected)
                {
                    lblStatus.Text = "SSH connection is active";
                    string command = ("ls -la");
                    string output = client.RunCommand(command).ToString();
                    listBox1.Text = output;
                }
                else
                {
                    lblStatus.Text = "SSH connection has failed";
                }
                //client.Disconnect();
            }
        }
Some help would be appreciated :-)

New Post: How to send results of client.RunCommand to a listbox WinForms C#

$
0
0
Instead of using
string output = client.RunCommand(command).ToString();
listBox1.Text = output;
use
var output = client.RunCommand(command)
listBox1.Items.Add(output.Result);

New Post: Stability while in beta; "stable" timeframe

$
0
0
I second the motion! This is great project and I don't want to see it die. I can certainly help and I am sure other people will help too!
Moving to GitHub will certainly help and will allow other people to contribute.

New Post: How to send results of client.RunCommand to a listbox WinForms C#

$
0
0
Great thanks, I'm getting the ls -la output into the listbox now, albeit all on one line but I can fix that.

Thanks for your help :-)

New Post: How to send results of client.RunCommand to a listbox WinForms C#

$
0
0
Outputting the results of ls -la or iostat to the listbox is okay, columns are a bit off, more formatting required.

This is okay for these commands, top for example doesn't display.
var output = client.RunCommand(command);
                string[] lines = Regex.Split(output.Result, "\n");

                //String[] lines = output.Result.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in lines)
                {
                    listBox1.Items.Add(line);
                    this.Invoke(new Action(() => listBox1.TopIndex = listBox1.Items.Count - 1));
                }

New Post: Upload limit

$
0
0
I can't say about whether or not there is a limit on SSH, but in looking at your code,do you think you could be consuming too many filehandles in your process?

You might want to use ProcessExplorer or some such to see if the filehandle resources are getting freed up?

New Post: Trouble using .RunCommand() with ssh.net

$
0
0
So I am trying to run a remote nodejs server with a few arguments and although I manage the start the server correctly i fail to pass on to the next command and the app fails after a 60 sec timeout. Here's my code:
SshClient ssh = new SshClient(myURL, 22, myUser, myPass);
string unixCommand = "/usr/local/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --port 4723 --full-reset --device-name \"iPhone 6\" --platform-name iOS --platform-version \"8.3\" --app \"myApp.app\" --browser-name iOS -l --log /Users/QA/Library/Logs/Appium/1.log";
    {
        ssh.Connect();
        ssh.RunCommand(unixCommand);
        ssh.Disconnect();
Thanks!

Commented Unassigned: System.InvalidOperationException: Dynamic operations can only be performed in homogenous AppDomain [2401]

$
0
0
Hi All,

I am trying to connect to FTP using your binaries and getting below error:
System.InvalidOperationException: Dynamic operations can only be performed in homogenous AppDomain. at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect()...

My scenario is I am using SharePoint 2013 List event receiver to upload file in SFTP shared location which is working successfully.
I am trying to read the file from same shared location and getting above error. The only thing which is different here is, for reading I am using SharePoint 2013 Timer Job.

Quick response would be appreciated.
Comments: ** Comment from web user: Cristabel **

Hi there, I am trying to connect to FTP using Renci.SshNet.dll and getting below error: Dynamic operations can only be performed in homogenous AppDomain. I'm using SharePoint 2013 and runing a Timer Job invoking SshNet.

BTW I can't get this UTL: http://sharepointchampion.blogspot.be/2014/06/systeminvalidoperationexception-dynamic.html

Thanks,
Cris

New Post: visual basic.net sftp downloading file with progress bar

$
0
0
hi
please help me i need a program in visual basic 2010 express to sftp download a file from server but with a progress bar because there is not any example here in vb.net for this.
many thanks in advance

New Post: client.RunCommand() is not working

$
0
0
 static void Main(string[] args)
        {
           PrivateKeyFile key = new PrivateKeyFile("private");
           using (var client = new SshClient("10.96.15.6", "admin", key))
            {
                client.Connect();
                client.RunCommand("xcommand dial number: 6712@XXXXXXXX.com");
                client.Disconnect();
            }
        }
The program hangs at the .RunCommand(). I am new to this, am i missing something really basic? It seems that this is the same code that works for other people and I know that the command is correct.

If I comment out the .runcommand() the program executes without error.

I appreciate any help in advanced.

Created Unassigned: SSH.NET sees files in list having Unicode symbols in names, but cant download them [2664]

$
0
0
On listing files on SFTP, I get the following file in the list:

./BCS_Emir_BCSCY_Routa_16032015a.Routa � BCS CY.csv_UVTR.txt

But on trying to download it with ReadAllBytes, I get the exception of type 'Renci.SshNet.Common.SftpPathNotFoundException'. It happens only on files with such symbols in their name, other files download fine.

New Post: Downloading and returning a non blocking stream of data using SSH.Net

$
0
0
I am using the ssh.net library for performing SFTP operations to work with large data files (>=500MB)

I am having an issue with how to return the data in a non-blocking way.

The ftpClient.DownloadFile() method signature is ok, when writing to a file or if there's some way I can instantiate the stream, but am having problems on how to use it when I want to return a stream without blocking.

All the examples I have seen so far will be writing the download to a Filestream. Nothing that just returns a stream

With .Net's built-in FTP, you just use response.GetResponseStream(), and it streams back the data, without blocking.

The only way round to using it in a return statement was writing to a temporary file. But this results in it being a blocking operation.

var tmpFilename = "temp.dat";
        int bufferSize = 4096;
        var sourceFile = "23-04-2015.dat";

        using (var stream = System.IO.File.Create(tmpFilename , bufferSize, System.IO.FileOptions.DeleteOnClose))
        {
            sftpClient.DownloadFile(sourceFile, stream);
            return stream;
        }
I don't want it to block but to stream back the data.

I also would like to avoid creating a temporary file.

Is there an alternative implementation to make it stream back the data?

Or is there an alternative stream I can instantiate(except for MemoryStream), that would work with large files?

Created Unassigned: Closing ForwardedPort ends with WSACancelBlockingCall [2666]

$
0
0
Hi, anytime I try to close forwarded port it ends with exception.

I'm using SSH.NET.2013.4.7 when switched to 2014.4.6b2 I got "A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll" instead, exactly in the same place.

here is sample class that replicates this error:

```
public class ExampleSSH
{
public static ConnectionInfo TunnelConfiguration { private get; set; }

public static ForwardedPortLocal ForwardedPort { get; private set; }

private static SshClient _currentTunnel;
public static SshClient CurrentTunnel
{
get
{
//establish connection if none
if (_currentTunnel == null)
{
_currentTunnel = new SshClient(TunnelConfiguration)
{
KeepAliveInterval = TimeSpan.FromMinutes(5)
};
//_currentTunnel.ErrorOccurred += (sender, args) => Log.Error(args.Exception);
//_currentTunnel.HostKeyReceived += (sender, args) => SSH.HandShake(args);
}

//connect if disconnected
if (_currentTunnel.IsConnected == false)
{
_currentTunnel.Connect();
//var currentShell = _currentTunnel.CreateShellStream("terminal", 80, 24, 800, 600, 1024);
//{
// currentShell.DataReceived += CurrentShellOnDataReceived;
//}
}

//forward ports if missing
if (!_currentTunnel.ForwardedPorts.Any())
{
ForwardedPort = new ForwardedPortLocal("localhost", Network.GetAvailablePort(DB.CurrentState), "localhost", 3306);

_currentTunnel.AddForwardedPort(ForwardedPort);

//ForwardedPort.RequestReceived += (sender, args) => Log.Output("port:" + args.OriginatorHost + ":" + args.OriginatorPort);
//ForwardedPort.Exception += (sender, args) => Log.Error(args.Exception);

ForwardedPort.Start();

Thread.Sleep(1000 * 10);

//here it dies with message: "A blocking operation was interrupted by a call to WSACancelBlockingCall"
ForwardedPort.Stop();
}

return _currentTunnel;
}
}
}
```

New Post: Windows phone 8 port farwarding

$
0
0
Hi I need to consume via c# a REST server via PortForwarding

I would like to use SSH.net this way
using (var client = new SshClient("server", "username", "password"))
 {

   client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
   client.Connect();
   var port = new ForwardedPortLocal("127.0.0.1",1001, serverAddress, serverPort);
   client.AddForwardedPort(port);
   port.Exception += delegate(object sender, ExceptionEventArgs e)
   {
        Console.WriteLine(e.Exception.ToString());
   };
   port.Start();

   //---START
               var url = new Uri("http://127.0.0.1:1001/SomeRestApi");

        var request = HttpWebRequest.Create(url);

        var response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse,
                                            request.EndGetResponse,
                                            null)
            .ContinueWith(task => (HttpWebResponse)task.Result);


   //---END

   port.Stop();
   client.Disconnect();
 }
The REST part is the one between ----START and ----END but it doesn't work. It gives the infamous Silverlight 'NotFoundException'.

Do you see something wrong with this code? Since I can't understand where it should be uncorrect.

Thanks

Stefano

New Post: Cancel a SFTP upload or download

$
0
0
hi Oleg can you please convert this code to visual basic.net

Created Unassigned: Does this support X11 forwarding? [2670]

$
0
0
I don't see any mention of X11 in the issues at all.

Created Unassigned: Don't throw ArgumentException on empty username [2672]

$
0
0
Currently the constructor for AuthenticationMethod throws an exception when the username is empty (String.Empty). This prevents from creating a connection with blank username (eg. Cisco routers).

The fix should be simple, just change
```
protected AuthenticationMethod(string username)
{
if (username.IsNullOrWhiteSpace())
throw new ArgumentException("username");

Username = username;
}
```
to:
```
protected AuthenticationMethod(string username)
{
if (username == null)
throw new ArgumentException("username");

Username = username;
}
```
Viewing all 2955 articles
Browse latest View live


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