Is E:\abedi a directory ?
You should specifiy a file path as argument for the FileStream constructor.
Hope this helps,
Gert
using Renci.SshNet;
namespace SshNetTests
{
class Program
{
public static void Main()
{
var privateKeyAuthenticationMethod = new PrivateKeyAuthenticationMethod("<user>",
new PrivateKeyFile(@"<path to private key>"));
var connectionInfo = new ConnectionInfo("<SSH server hostname or IP address>",
22,
"<user>",
ProxyTypes.Http,
"<proxy server hostname or IP address>",
8080,
"<proxy user>",
"<proxy password>",
privateKeyAuthenticationMethod);
using (var sftpClient = new SftpClient(connectionInfo))
{
sftpClient.Connect();
}
}
}
}
using (var client = new SftpClient(...))
{
client.ErrorOccurred += (sender, args) => Console.WriteLine(args.Exception);
client.Connect();
...
}
Hi,
first of all, thank you for providing this useful library.
I use version 2014.4.6.0, built from the source available in the Downloads section. I experience the same issue. Downloading any file above ~15k fails. Here's the code (skeleton with "real" values where applicable):
```
using (var sftp = new SftpClient(url, user, pw))
{
sftp.Connect();
sftp.SendKeepAlive();
sftp.OperationTimeout = TimeSpan.FromSeconds(3600);
var dirFiles = sftpClient.ListDirectory("outgoing"); // find one file: "outgoing/a.zip"
string remoteFile = dirFiles[0];
string localFile = @"C:\a.zip";
using (FileStream downloadFS = new FileStream(localFile, FileMode.Create, FileAccess.Write))
{
sftpClient.DownloadFile(remoteFile, downloadFS); // this is where the error occurs
}
sftp.Disconnect();
}
```
StackTrace:
```
at Renci.SshNet.Sftp.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestRead(Byte[] handle, UInt64 offset, UInt32 length)\
at Renci.SshNet.SftpClient.InternalDownloadFile(String path, Stream output, SftpDownloadAsyncResult asyncResult, Action`1 downloadCallback)
at Renci.SshNet.SftpClient.DownloadFile(String path, Stream output, Action`1 downloadCallback)
```
__NOTE__
The connection, file listing, etc. works great. And there is no issue with small-size files. Sample __a.zip__ is about 120k, which doesn't look excessive. Curiously, I was able to download much larger files using a previous (2013.4.7.0) version of SSH.NET.
If there's another way of requesting a download, I'm happy to re-implement.
Thanks for any pointers/help.
Eric
» ssh test "nohup /dev/null"; echo $?
nohup: failed to run command ‘/dev/null’: Permission denied
126
Eric,
Are you able to reproduce this issue consistently with 2014.4.6.0 beta 1?
I've been finishing up some changes lately, but after that I'd really like to get to the bottom of this.
You can't reproduce this issue against a public SSH server by any chance ?
Cheers,
Gert
Gert,
thanks for your reply. I built the SSH.NET I use from the 2014.4.6.0 beta 1 code base.
Good thing you suggested testing on a public SSH server. I set up a small SFTP server at work and tested downdloads/uploads from there - _successfully_. So the issue is not the size, although I do think it helps manifest it. But downloads still fail with the same file on the customer's SFTP site. And for maximum confusion: I can download/upload the same file from the FileZilla UI.
Here's where my SFTP server and the customer's server differ: the customer's SFTP activity is monitored programmatically. When the download completes for a given file, I can't delete it; instead, the system automatically relocates it to a subfolder on the SFTP, as though this behavior was event-driven. Same thing for uploads: once the transfer completes, the file is automatically moved to a subfolder. I can't be more specific about it - that's all I was told.
In any case, I would speculate that once a number of bytes (= buffer size?) have been read, when SSH.NET tries to read in the next buffer, that monitoring system seems to close the door on it.
Hope this helps.
Eric
126 nohup found the utility program but could not invoke it.
RunCommand() is not the same like starting the command in a full (Putty-)Shell.C:\Windows\System32>"c:\Program Files (x86)\PuTTY\plink.exe" test "nohup /dev/null"
nohup: failed to run command ÔÇÿ/dev/nullÔÇÖ: Permission denied
This does the same like RunCommand() in SSH.NET.Hello Gert,
Thanks for the library it is really good.
It seems like I have hit the same problem - I am fine reading small files (40Kb) but when I went to a slightly larger file(140Kb) - I hit the same disconnect error.
I am using almost exactly the same code as Eric and I can download the same file using Filezilla without any problems as well.
The stack trace is:
at Renci.SshNet.Sftp.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestRead(Byte[] handle, UInt64 offset, UInt32 length)
at Renci.SshNet.SftpClient.InternalDownloadFile(String path, Stream output, SftpDownloadAsyncResult asyncResult, Action`1 downloadCallback)
at Renci.SshNet.SftpClient.DownloadFile(String path, Stream output, Action`1 downloadCallback)
I have tried tinkering with:
sftp.BufferSize = 1024 * 256 - 50;
sftp.SendKeepAlive();
sftp.OperationTimeout = TimeSpan.FromSeconds(3600);
sftp.ConnectionInfo.Timeout = TimeSpan.FromSeconds(3600);
Nothing seems to help.
Many Thanks,
Adrian
Adrian,
You don't happen to have a public server available on which I can reproduce this issue ?
Can you check if any data at all was written to the stream after the exception is thrown ?
Do you have access to the logs on the SSH server ?
I'd really like to fix this issue before releasing a new beta.
Thanks!
Gert