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

New Post: Proxy issue with Sftp class (client) with Renci.SshNet library

$
0
0
hi friend

how to connect to sftp server with (http proxy) AND (private key) ????

thanks :X

New Post: uploading encrypt data

$
0
0
hi friend

i using this code for connecting to sftp server :
 var connectionInfo = new PasswordConnectionInfo(txtHost.Text, 22, txtUsername.Text, txtPassword.Text, ProxyTypes.Http, "209.xxx.xxx.xx", 3128,"proxyUser","proxyPass");
                sftp = new SftpClient(connectionInfo);
                try
                {
                    sftp.Connect();
                    addItemToListBox("Connect", "Connect to server Success.");
                   
                }
now , when sniffing my connection with wireshark , i can see my http request !!!

how to encrypt my requests and packets ???
thanks

Source code checked in, #40668

$
0
0
Added internal IForwardPort interface to allow mocking of forwarded ports. Added internal IChannelDirectTcpip and IChannelForwardedTcpip interfaces. Extended ISession and IConnection interface to allow for unit tests of ChannelDirectTcpip. Modified ChannelDirectTcpip to interrupt blocking receive when the ForwardedPort is closed. Shutdown send of socket when EOF is received. Close the socket when unhandled exception occurs in session message loop, and when server terminates connection using SSH_MSG_DISCONNECT message. Fixes issue #1558. When stopping ForwardedLocalPort, block until all channels have been closed or until Connection.Timeout has elapsed.

Edited Issue: Forwarded Port channels can get stuck waiting [1558]

$
0
0
I was testing ssh.net with 2 ForwardedPortLocals. When a connection is established, a port is forwarded properly but the channel is sometimes not closed, depending on how the local port was closed.

It can get stuck waiting for an EOF that never comes in ChannelDirectTcpip.cs Bind()
System.Threading.WaitHandle.WaitAny(new WaitHandle[] { this._channelEof });

this is because the while loop above can exit gracefully if _socket.CanRead() returns false. In this scenario no CloseMessage was ever sent so it will sit waiting forever. I suggest adding:

this.SendMessage( new ChannelCloseMessage( this.RemoteChannelNumber ) );

after the while loop or moving the WaitAny line into Close();
Comments: ** Comment from web user: drieseng **

This should be fixed in changeset 40668.

Let me know if this fixes the problem for you.

Source code checked in, #40669

New Post: SCP upload speed

$
0
0
Comparing WinSCP Upload speed and SSH.Net upload speed (over a WiFi connection, but same external conditions and repeated a few times):

WinSCP 1.3MB/s
SSH.net 0.4MB/s

(I saw a similar speed with sharpssh, that I recently replaced due to the debugging of problems taking longer and longer and being more and more unsuccessful.)

Download speed generally seemed fine at 1MB/s+ with the same setup.

Is there something I can do to tweak this?

New Post: SftpClient FileUpload asynchronous version

$
0
0
There is no direct asynchronous file upload method. They may have support in future. In the meantime you may use this extension method. It worked for me. :)
public static class SftpClientExtension
{
public static async Task UploadFileAsync(this SftpClient client, Stream input, string path, Action<ulong> uploadCallback = null)
    {
        await Task.Factory.FromAsync(client.BeginUploadFile(input, path, null, null, uploadCallback), client.EndUploadFile);
    }
}

Created Unassigned: issue with creating sockets with IPV6 address [2560]

$
0
0
Hi,
While creating a socket, I have specified that it be connected to the localhost(Windows 2008 R2 64 bit machine) since my SFTP server is running there. It started throwing exceptions that socket could not be created.
After successfully connecting using the same code from a different machine(32bit Windows 7), I understood that the issue is just in this machine. I have put breakpoints in the code and finally got to this...
__File__ : Renci.SshNet\Common\Extensions.NET.cs.
__Method__ : internal static IPAddress GetIPAddress(this string host)

This method is taking the first address and on some machines, the IPV6 address is first. With this, it is not able to create a socket and hence it is failing.

Since I am using the code (and not just binaries), I can go ahead change the code to check the AddressFamily.InterNetwork and return the IPv4 address. But, should this be considered as a change which will be incorporated by someone who is contributing? Or, is my thought process wrong on this?

Created Unassigned: Disconnect() and Dispose() hangs of network device disappeared [2562]

$
0
0
Hi,

I am currently using SSH.NET revision 40631. I am working with a
embedded Linux device that's connected via a USB Ethernet Gadget.
If the USB connection is already unplugged the Disconnect() method as well
as the Dispose() method of SshClient / ScpClient does not return any more.

In difference to unplugging a Ethernet cable unplugging the USB cable causes
removal of the network device and not only it's connected state.

Can anybody please help me?

Yours
Ulrich

Created Unassigned: CreateShellStream closes the conenction : "An established connection was aborted by the server" [2563]

$
0
0
Dear friends, I am using SSHNET for many connections. I use CreateShellStream to find an output.
One kind of hosts (the old one, BusyBox v1.00-pre10) closes the connection on
```
using (var stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
```
It happens only with that type of hosts.

```
using (var ssh = new SshClient(ip, user, pass))
{
ssh.Connect();
ssh.SendKeepAlive();

using (var stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
{
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
...
```
```

at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.ChannelSession.SendPseudoTerminalRequest(String environmentVariable, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, IDictionary`2 terminalModeValues)
at Renci.SshNet.ShellStream..ctor(Session session, String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 maxLines, IDictionary`2 terminalModeValues)
at Renci.SshNet.SshClient.CreateShellStream(String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 bufferSize, IDictionary`2 terminalModeValues)
at Renci.SshNet.SshClient.CreateShellStream(String terminalName, UInt32 columns, UInt32 rows, UInt32 width, UInt32 height, Int32 bufferSize)
at wifi_ap_info.Program.ssidcheck2(String ip, String user, String pass) in c:\Users\oleg\Docs\wifi_ap_info\ssh client\Program.cs:line 413

```

Does anyone solved this problem?
Thank You.

Commented 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: Schmid **

Gert,

it seams the behaviour is not reproducable without our embedded device.
We would like to send you such one. Would you please send me your
contact?

Thanks
Ulrich

Created Unassigned: Session Operation has timed out [2564]

$
0
0
Hi,

I've seen a few posts on this and while I've tried some of the fixes suggested in them, none of them seem to be working. This seems to be present regardless of file size, I've tried a 5MB file, 20MB, 100MB and 512MB...the final solution if I can get this working needs to be capable of transferring about 10GB or so.

I'm still getting to grips with this library so it might be something that I'm doing wrong and not in fact an issue at all, but looking round I've seen a few pieces here and there so it might be a recurring issue. I have also tried with just the standard buffersize, but seeing the suggestions that this might fix it, I added in the line to specify it explicitly.

Testing it with the SFTP client results in a successful transfer and a very quick one at that, although it is going from host to guest VM so that is to be expected!

Thinking it might be something to do with how I'm initializing the I took a look inside the ConnectionInfo and saw that the client is using SSH2.0 could this be affecting the size?

I have also tested the transfer using the Putty SCP command line tool and it successfully completes without any issues.

```
sshClient.Connect();
if (sshClient.IsConnected)
{
try
{
Console.WriteLine("Connection successful!");
Console.WriteLine();
Console.WriteLine(string.Format("Checking for existence of {0} directory...", destDir));
var locateDir = sshClient.RunCommand(string.Format("if [ -d {0} ]; then echo \"true\"; else echo \"false\"; fi", destDir));
var dirExixts = Convert.ToBoolean(locateDir.Result.Replace("\n", ""));
if (dirExixts)
{
Console.WriteLine("Directory already exists...");
}
else
{
Console.WriteLine("Directory not found, attempting to create directory...");
var createDir = sshClient.RunCommand(string.Format("mkdir {0}", destDir));
if (createDir.ExitStatus == 0)
Console.WriteLine("Destination directory successfully created!");
else
{
throw new Exception(string.Format("Failed to create remote directory: {0}. Error: {1}", destDir, createDir.Error));
}
}

Console.WriteLine();
Console.WriteLine("Initiating SCP transfer...");
var scpClient = new ScpClient(sshClient.ConnectionInfo);
scpClient.BufferSize = 1024 * 16 - 64;
scpClient.Connect();
var file = new FileInfo(@"C:\Users\DevTest\Downloads\20MB.zip");
using (var stream = File.OpenRead(file.FullName))
{
scpClient.Upload(stream, destDir + "/" + file.Name);
}
Console.WriteLine("SCP transfer complete!");
Console.WriteLine();
Console.WriteLine(string.Format("Disconnection from {0}..."));

sshClient.Disconnect();

Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("An unexpected error has occured");
Console.WriteLine(string.Format("Exception: {0}", ex.Message));
sshClient.Disconnect();
}
}
else
{
Console.WriteLine("Connection failed...");
}
```

If needs be as well, I am running this in a VM so can snapshot and sort out sending a copy of the environment over to see if you're able to reproduce in.

After some more digging, specifically finding this site http://winscp.net/eng/docs/scp it looks like SCP has a file size maximum of 4GB anyway making it impractical for the 10GB target I need to hit, however the SFTP function works fine so I can carry on with that aspect of this library but some insight into the issue anyway would be interesting.

New Post: sftp download file

$
0
0
hi
i can't find sample code for downloading file

uploading file is very easy but i cant download file from server

Please attach a sample code

thanks

New Post: sftp download file

$
0
0
this is my downloading file code

public void download()
    {

        if (connection_flag == false)
            connect();


        string downloadedFileName = "upload/01fe46c977e2cbf2159b571a2503a686.zip";
        using (var stream = new FileStream("E:\\abedi", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
        {

            //download the file to our local path
            sftp.DownloadFile(downloadedFileName, stream);
            stream.Close();

        }
    }
error doanloading is : Access to the path 'E:\abedi' is denied.

New Post: sftp download file

$
0
0
using (var client = new SftpClient("<address>", <port>, <uid>, "<pw>"))
{
client.Connect();
List<Renci.SshNet.Sftp.SftpFile> Files = client.ListDirectory("<ftp file directory>").ToList();

foreach (Renci.SshNet.Sftp.SftpFile CurrentFile in Files)
{
  /// Download into file stream
       FileStream fs = new FileStream(Folder + CurrentFile.Name, FileMode.Create);
       client.DownloadFile(CurrentFile.Name, fs);

       /// Close file stream
       fs.Close();
}

client.Disconnect();
}


Hope this helps.

Created Issue: Inconsistent dealing with empty hostname and zero 0 in ForwardedPort* [2566]

$
0
0
We currently do not deal with a zero-length hostname and / or zero port in a consistent way in our ForwardedPort implementations.

ForwardedPortLocal:
* we do not bind to all local IP addresses when BoundHost is zero-length string.
* we update BoundPort with the actual port that has been assigned after starting the forwarded port.
* we do not update BoundHost

ForwardedPortDynamic:
* we do bind to all local IP addresses when BoundHost is zero-length string.
* we do not update BoundPort with the actual port that has been assigned after starting the forwarded port.
* we do not update BoundHost

By updating BoundPort (and not retaining the original value), we'll use the assigned port number as is if we'd stop and restart the forwarded port.

We should perhaps introduce a LocalEndpoint property which reflects the assigned value when the forwarded port is started, and which returns the original IPEndPoint when the port is stopped.

Still need to check ForwardedPortRemote.

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

Ulrich,

Send me your email adres, and I'll respond with my contact information.

Regards,
Gert

Commented 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: Schmid **

Gert,

thanks for your response.
My contact: schmid@ixxat.de

Yours,
Ulrich

New Post: Generating DSA and RSA keys

$
0
0
I have been trying to figure out if I can use this library to generate DSA and RSA keys. I have looked through the test inside Classes/Security but most of them are just stubs and it's unclear to me if this functionality exists or not.

Could someone point me in the direction of some info on it and how this can be done?

New Post: Generating DSA and RSA keys

$
0
0
This is currently not available in SSH.NET, and it's not an area I'll likely work on in the near future.
Why don't you just generate the key with readily available OSS tools (e.g. openssh) ?
Viewing all 2955 articles
Browse latest View live


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