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

Closed 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: I'm closing this issue, but don't hesitate to reopen it.

Closed Unassigned: Connect without ssh command? [1698]

$
0
0
I am attempting to transfer a file using ScpClient.
The user I have is restricted by rssh to only be able to use the scp command. It does not have shell access at all.
When transferring from the command line, the transfer works flawlessly. Same thing if I use the root user and my application. So I do not think there is anything wrong with my code or the host machine.

Does SSH.NET require commands other than SCP to authenticate maybe? I have tried going through the code but could not figure this out.

When using this restricted account, SSH.NET reports that no authentication method could be negotiated. I am at a bit of a loss right now. Is anybody aware of limitations of this kind?
Comments: Issues was not related to ssh.net.

Edited Issue: Random NullReferenceException during SFTP disconnect [1587]

$
0
0
Hi,

I have a windows service which synchronizes through SFTP with custom specified intervals, it is installed on 3 machines with 3 different operating systems. On one machine an exception occurs randomly at the disconnect event and I cannot figure out why. On the other machines the problem occurred only once, on this particular machine it occurs every day, sometimes multiple times daily. The application is multithreaded, more than one synchronization jobs can be executed simultaneously. The exception happens only at disconnect, not during upload/download, and always on "empty" sessions where the thread just connects, retrieves a filelist and then disconnects when it notices that there is currently nothing to synchronize.

The exception is a NullReferenceException, message from the log:

```
[2013.05.27. 1:28:45] UNHANDLED EXCEPTION! Message: Az objektumhivatkozás nincs beállítva semmilyen objektumpéldányra. - Stack trace: a következő helyen: Renci.SshNet.Sftp.SubsystemSession.RaiseError(Exception error)
a következő helyen: Renci.SshNet.Sftp.SubsystemSession.Session_ErrorOccured(Object sender, ExceptionEventArgs e)
a következő helyen: System.EventHandler`1.Invoke(Object sender, TEventArgs e)
a következő helyen: Renci.SshNet.Session.RaiseError(Exception exp)
a következő helyen: Renci.SshNet.Session.MessageListener()
a következő helyen: Renci.SshNet.Session.<Connect>b__4()
a következő helyen: Renci.SshNet.Session.<>c__DisplayClass3d.<ExecuteThread>b__3c(Object o)
a következő helyen: System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
a következő helyen: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
a következő helyen: System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
a következő helyen: System.Threading.ThreadPoolWorkQueue.Dispatch()
a következő helyen: System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
```

The code (most important part):

```
private SftpClient sftpClient = null;

......................................

public void Synchronize( Object stateObject )
{
//................
try
{
sftpClient = new SftpClient( Address, Port, Username, Password ); // don't want to use "using" because of the finally block
try
{
Log( "Connecting to server" );
sftpClient.Connect();
}
catch (Exception ex)
{
Log( "Error while connecting: " + ex.Message );
return; // finally block still will run
}
// ............. filelist, upload/download (this is a large block), everything in try/catch
}
finally
{
if (sftpClient != null)
{
if (sftpClient.IsConnected)
{
Log( "Disconnecting from server" );
sftpClient.Disconnect();
}
sftpClient.Dispose();
}
}
```

I attached the complete log file, please check it out, I don't know why the error is coming and how to avoid it. (Besides the "solution" to enclose the two method calls in the finally block in a try/catch block itself, which isn't too pretty.) Please help if you can.

Thank you, best regards,
Dester
Comments: ** Comment from web user: drieseng **

I recently fixed this issue (changeset 34793).
Please build from SVN, or wait for the upcoming (beta) release.

Note this is a duplicate of issue 1298.

Edited Issue: sftpfilestream read is very slow. [1919]

$
0
0
Sftpfile stream is very slow it took 1hr 15 mins for 400mb file.
Is there any way to increase the read buffer of the sftpfilestream.
sftp.buffersize is for upload i believe. But i tried changing it no luck.

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: drieseng **

Would it be possible to provide more details ?

Commented Unassigned: SSHNet and Visual basic- login [1882]

$
0
0
Hello! I work for a company called GGServers, and we sell minecraft hosting. What I'm currently working on, is an application in VB to streamline the process of ssh remote management. What this program will do, is instead of having to type commands in something like PuTTY, You click buttons to run commonly used commands, like htop to show the hardware monitor, and others to delete files, or restart Multicraft daemons.
The problem I'm currently running into is the actual login part of this. here's some examples of what I've got going on.

The Interface: http://puu.sh/6FQ5J.png
```
Public Class ggsmain

Public Sub login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click

Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(hostname.Text.ToString, usrname.Text.ToString, password.Text.ToString)
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
Try
Using sshClient
sshClient.Connect()
End Using
Catch ex As Exception
cmds.Visible = True
End Try
End Sub

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(hostname.Text.ToString, usrname.Text.ToString, password.Text.ToString)
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
Using sshClient

Dim cmd As Renci.SshNet.SshCommand
cmd = sshClient.RunCommand("htop")
output.Text = cmd.Result
End Using
End Sub
End Class
```

and finally, the error output:
With port appended to hostname:
```
A first chance exception of type 'System.ArgumentException' occurred in Renci.SshNet.dll
A first chance exception of type 'Renci.SshNet.Common.SshConnectionException' occurred in Renci.SshNet.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'Renci.SshNet.Common.SshConnectionException' occurred in Renci.SshNet.dll
A first chance exception of type 'System.ArgumentException' occurred in Renci.SshNet.dll
A first chance exception of type 'System.ArgumentException' occurred in Renci.SshNet.dll
(the more detailed error output) http://puu.sh/6FQbm.png
```
and without the port appended:

http://puu.sh/6FQfR.png (it doesn't show the output window for some reason, like the other)

Note that I can connect to the host with the information I used in my app in PuTTY and send commands normally.

Considering my at best intermediate level of proficiency in VB, I should probably not be attempting this, however I learn fast, and am Self taught in VB- never took classes for it. I literally installed it and played around with it until I was able to build multimedia applications(music player using wmp object and playlist support)
I feel like if I can get a little insight with this issue, I would be able to pick it up. Once I get the application to connect, and hold said connection open, I can then begin to add more commands to send to ssh host, and print them to the big black box(label) on the form

Thanks for your time, and I hope someone is able to help me. I'll be happy to provide more information if necessary
Comments: ** Comment from web user: drieseng **

The PasswordConnectionInfo(string host, string username, string password) ctor uses port 22 to connect to the SSH server.

If your server listens on another port, then you should use this overload:
PasswordConnectionInfo(string host, int port, string username, string password)

Let me know if this helps,
Gert

Closed Unassigned: SSHNET Issue [1789]

$
0
0
I want to use SSH.Net library in my visual studio 2010 project for that i need to refer SSHNET project as a example. but the SSHNET project which i download from link https://sshnet.codeplex.com/ by clicking download button is created in visual studio 2012.
so is there any way to open it in vs 2010 ? or is there any link from where i can download SSHNET which is created in vs 2010 ?
Comments: No response from requester.

Commented Issue: SftpClient.UploadFile Truncates Uploaded File [1533]

$
0
0
I'm uploading a file with 7MB size and the file is truncated to 4.5MB more or less.

I tried a Flush on the Stream but I always has the error

```
streamFile = // Load Stream
streamFile.Flush();
streamFile.Position = 0;

try
{
// Connect to sftp site
this._sftpClient.Connect();

if (!this._sftpClient.IsConnected)
throw new Exception(string.Format("Could'n connect to server {0}", this._sftpClient.ConnectionInfo.Host));

this._sftpClient.UploadFile(streamFile, string.Format("{0}{1}", this.RelativePath, this.FileName), true);
}
catch (Exception error)
{
logger.Error("Error uploading file.", error);
}
finally
{
if (this._sftpClient.IsConnected)
{
try
{ this._sftpClient.Disconnect(); }
catch (Exception error)
{ logger.Error("Couldn't disconnect global SFTP connection.", error); }
}
}
```
Comments: ** Comment from web user: drieseng **

Can you please verify that this issue is fixed in the latest release (or in a version built from SVN) ?


Source code checked in, #34968

Source code checked in, #34969

Source code checked in, #34970

$
0
0
Fixed another reference in XML doc.

Source code checked in, #34971

$
0
0
Document few more fixed, and correct typo.

Source code checked in, #34972

$
0
0
Use batching to simplify build script.

New Post: About the speed

$
0
0
Performance of ssh.net should have improved significantly with the changes I committed yesterday.
There's still room for improvement though.

Source code checked in, #34979

$
0
0
Added ClientChannel, ServerChannel and ChannelOpenConfirmedEventArgs source files, and do not emit debug symbols in release configuration.

Source code checked in, #34980

$
0
0
Move all shared assembly-level attribute to CommonAssemblyInfo.cs.

Source code checked in, #34981

$
0
0
Add support for generating help doc.

New Post: About the speed

$
0
0
Super, I will test it. Thaks a lot.
pq

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,

Please apologize the delay. I did not have the time for providing a demo the last days.
The demo creates a temporary file structure an cyclically uploads it to the remote device.
I'm referencing Renci.SshNet.NET35.dll and running the release build.

I'm using revision 25006 in which I already integrated a patch from a SSH.NET discussion for
using absolute path strings (see attached file).

Thank you for reopening the issue.

Ulrich

```

using System;
using System.Text;
using Renci.SshNet;
using System.IO;


namespace ConsoleApplication1
{
class Program
{
const string address = "169.254.177.104";
const string user = "root";
const string pass = "password";

const string mRemoteDir = "/tmp/test/";


static SshClient mSsh;
static ScpClient mScp;

//************************************************************************
static int Execute(string command)
{
return Execute(command, false);
}

//************************************************************************
static int Execute(string command, bool silent)
{
if (!silent)
{
Console.WriteLine(string.Format("SSH.Execute : {0}", command));
}

SshCommand cmd = mSsh.RunCommand(command);
if (!silent)
{
Console.WriteLine(String.Format("ExitCode: {0}", cmd.ExitStatus));
if (!String.IsNullOrEmpty(cmd.Result))
{
Console.WriteLine(string.Format("Result:\n{0}", cmd.Result));
}
if (!String.IsNullOrEmpty(cmd.Error))
{
Console.WriteLine(string.Format("Error:\n{0}", cmd.Error));
}
}
return cmd.ExitStatus;
}

//************************************************************************
static void Main(string[] args)
{
var localDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
try
{
Directory.CreateDirectory(localDir);
CreateTestData(localDir);

using (mSsh = new SshClient(address, user, pass))
{
mSsh.Connect();

using (mScp = new ScpClient(address, user, pass))
{
mScp.Connect();
mScp.ErrorOccurred += new EventHandler<Renci.SshNet.Common.ExceptionEventArgs>(mScp_ErrorOccurred);
mScp.Uploading += new EventHandler<Renci.SshNet.Common.ScpUploadEventArgs>(mScp_Uploading);

for (int i = 0; i < 10; ++i)
{
UploadDir(localDir, mRemoteDir);
}
}
}
}
catch (System.Exception ex)
{
Console.WriteLine(String.Format("Exception:\n{0}", ex));
}
finally
{
if (Directory.Exists(localDir))
{
Directory.Delete(localDir);
}
}

Console.WriteLine("Done");
Console.ReadLine();
}


//*************************************************************************
static void mScp_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
{
Console.WriteLine(String.Format("Error: {0}", e));
}


//*************************************************************************
static void mScp_Uploading(object sender, Renci.SshNet.Common.ScpUploadEventArgs e)
{
//Console.WriteLine(String.Format("Uploading {0} ({1}/{2})"
// , e.Filename
// , e.Uploaded
// , e.Size));
}

//*************************************************************************
private static void UploadDir(string localDir, string remoteDir)
{
string remoteDirPath = remoteDir.TrimEnd('/');
Execute(String.Format("rm -rf {0}", remoteDirPath), true);

Console.WriteLine("Upload to " + remoteDir);
DateTime startTime = DateTime.Now;
mScp.Upload(new DirectoryInfo(localDir)
, remoteDirPath);

Console.WriteLine("{0}", DateTime.Now - startTime);

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(String.Format("Valid : {0}"
, ValidateUpload(localDir, remoteDirPath)));
Console.ResetColor();
}

//*************************************************************************
private static void CreateTestData(string localDir)
{
CreateTestFiles(localDir);
for (int subDirIndex = 0; subDirIndex < 1; ++subDirIndex)
{
var subDir = Path.Combine(localDir, subDirIndex.ToString());
Directory.CreateDirectory(subDir);
CreateTestFiles(subDir);
}
}

//*************************************************************************
private static void CreateTestFiles(string dir)
{
var fileContent = new StringBuilder("HelloWorld\n");

for (int fileIndex = 1; fileIndex < 20; ++fileIndex)
{
var fileName = String.Format("{0}.txt", fileIndex);
var filePath = Path.Combine(dir, fileName);
fileContent.Append(fileContent.ToString());
File.WriteAllText(filePath, fileContent.ToString());
}
}

//*************************************************************************
private static bool DoRecursive( string localDir
, string remoteDir
, Func<string, string, bool> directoryDelegate
, Func<string, string, bool> fileDelegate)
{
bool result = true;

result &= directoryDelegate(localDir, remoteDir);

foreach (string localFile in Directory.GetFiles(localDir))
{
string remoteFile = String.Format("{0}/{1}"
, remoteDir
, Path.GetFileName(localFile));
result &= fileDelegate(localFile, remoteFile);
}

foreach (string localSubDir in Directory.GetDirectories(localDir))
{
string remoteSubDir = String.Format("{0}/{1}"
, remoteDir
, Path.GetFileName(localSubDir));
result &= DoRecursive( localSubDir
, remoteSubDir
, directoryDelegate
, fileDelegate);
}

return result;
}


//*************************************************************************
private static bool ValidateUpload(string localDir, string remoteDir)
{
return DoRecursive(localDir, remoteDir
, (locDir, rmtDir) =>
{
bool validDir= true;
if (0 != Execute(String.Format("[ -d {0} ]", rmtDir), true))
{
Console.WriteLine(String.Format("Missing remote directory {0}"
, rmtDir));
validDir = false;
}
return validDir;
}
, (locFile, rmtFile) =>
{
bool validFile = true;
if (0 != Execute(String.Format("[ -f {0} ]", rmtFile), true))
{
Console.WriteLine(String.Format("Missing remote file {0}"
, rmtFile));
validFile = false;
}
return validFile;
}
);
}
}
}

```

The output is completely curious:
```
Upload to /tmp/test/
00:00:09.0710000
Missing remote file /tmp/test/0/8.txt
Missing remote file /tmp/test/0/9.txt
Valid : False
Upload to /tmp/test/
00:00:09.0390000
Missing remote file /tmp/test/0/9.txt
Valid : False
Upload to /tmp/test/
00:00:09.0390000
Valid : True
Upload to /tmp/test/
00:00:09.0460000
Missing remote file /tmp/test/0/8.txt
Missing remote file /tmp/test/0/9.txt
Valid : False
```

New Post: ssh conversation

$
0
0
Any ideas, please?
I just need a basic example of ssh conversation.

Thanks.
Viewing all 2955 articles
Browse latest View live


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