This project is read-only.

how to use SFTP server response

Apr 29, 2012 at 5:39 PM
Edited Apr 29, 2012 at 5:40 PM

Hi,

I'm a new member on codeplex.com. I'm very interested to SSH.NET library. Actually I use it to write a little client to have SFTP functionalities. I used the .dll library (binary) and added it to my project in Visual Studio.

I wrote a SFTP class (structure) and implements some methods. I want to do it like this because of using MVC and don't want to use it directly into the View (GUI).

Now, I have a little problem with the server response messages? How can I write a method to use them? I only found public string Response { get; set; } in the AuthenticationPrompt class.



using System;
using Renci.SshNet;
using Renci.SshNet.Sftp;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Collections.Generic;

namespace TestSuite
{
  class SFTP
  {
    //******************************private Fields**********************************************************
    #region SFTP class variables
    private SftpClient _client;
    private Server _server;
    private User _user;
    private string statusMessage;
    private object BUFFER;
    private object bytes;
    private int _statusCode;
    private string result;
    private Socket sftpSocket = null;
    private bool _doVerbose;
    #endregion

    //******************************Constructor**********************************************************
    #region SFTP class variables
    public SFTP(Server server, User user)
    {
      this.Server = server;
      this.User = user;
      this.Client = new SftpClient(this.Server.ServerIP, this.User.UserName, this.User.Password);
    }
    #endregion

    //******************************Properties**********************************************************
    #region SFTP class variables
    public Server Server
    {
      get { return _server; }
      set { if (value != null) _server = value; }
    }

    public User User
    {
      get { return _user; }
      set { if (value != null) _user = value; }
    }

    public SftpClient Client
    {
      get { return _client; }
      set { if (value != null) _client = value; }
    }
    #endregion

    //******************************Methods*********************************************************
    #region SFTP class methods

    #region SftpLogin
    /// <summary>
    /// 
    /// </summary>
    public void SftpLogin()
    {
      this.Client.Connect();
    }
    #endregion



I read about examples in the source package of SSH.Net, but I didn't found anything?

best regards
Apr 29, 2012 at 6:18 PM

Hello

I am not sure what you want to do.

There are 3 types of clients, and their typical uses:

  • SshClient - Run commands, like 'ls', or create a shell for those who dare to.
  • SftpClient - FTP-like, for uploading and downloading files, get/set attributes, get/set write/access times, list/create/delete directories, and lots more.
  • ScpClient - Upload and download of files (nothing more)

So if you want to run commands remotely, you should use SshClient, if you are only interested in file operations, you should use SftpClient, if you only need upload/download you could use ScpClient, but I think using SftpClient would be the better choice if you want to do more file operations later in development.

For SftpClient examples, go to Source, and on the right hand side click Browse, then navigate as follows: Renci.SshClient -> Renci.SshNetTests -> SftpClientTests.

If you have more questions, please post here.

Apr 29, 2012 at 6:46 PM

Hi,

I guess SftpClient is the right way for me because of will having features like listDirectory, download, upload, delete.....

I downloaded the Renci.SshNet but can't find a folder like Renci.SshNetTests?

best regards

May 1, 2012 at 3:40 PM

To find Renci.SshNetTests simply check out latest code using SVN client.

Thanks,

Oleg

May 1, 2012 at 4:21 PM
Edited May 1, 2012 at 4:21 PM

Hi Oleg,

We made in our project the .dll running with connecting by password or key. Now we are on the way to make a method to give out the server response error codes. We need something like a response error message to cut out the return code.

Which Object got this method? I can't find something in the source code where you handle this?

 

best regards