SFTP with .NET 3.5

I need to connect to an SFTP server to download and upload files using C # /. NET 3.5.

Does the .NET 3.5 environment provide any built-in tools / mechanisms / libraries for connecting to the SFTP server for downloading and uploading files?

+3
source share
7 answers

There are commercial solutions:

... and for free:

I personally have no experience with any of them.

+4
source

There is no SFTP support in the .NET framework in any version.


Sanj , WinSCP, . , WinSCP.NET, , .NET WinSCP.

WinSCP NuGet.

# SFTP:

// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "example.com",
    UserName = "user",
    Password = "mypassword",
    SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

using (Session session = new Session())
{
    // Connect
    session.Open(sessionOptions);

    // Upload files
    session.PutFiles(@"d:\toupload\*", "/home/user/").Check();
}

VB.NET:

' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
    .Protocol = Protocol.Sftp
    .HostName = "example.com"
    .UserName = "user"
    .Password = "mypassword"
    .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With

Using session As New Session
    ' Connect
    session.Open(sessionOptions)

    ' Upload files
    session.PutFiles("d:\toupload\*", "/home/user/").Check()
End Using

( ).


WinSCP GUI SFTP-, , , #, VB.NET PowerShell.

enter image description here


, - WinSCP, .NET-. , .NET framework. , -.

.NET SFTP . SSH.NET, .

( WinSCP)

+2

,.NET SFTP-. WinSCP - , . , PayPal.

, / . .NET- , .

+1

WinSCP. , , . COM , - : . ini.

  const string logname = "log.xml";
            string username = ini.IniReadValue("sftp", "Username");
            string password = ini.IniReadValue("sftp", "Password");
            string remotehost = ini.IniReadValue("sftp", "Remote Host");
            string dloadpath = ini.IniReadValue("Download", "Local Path");

            Process winscp = new Process();
            winscp.StartInfo.FileName = @ini.IniReadValue("winscp", "compath");
            winscp.StartInfo.Arguments = "/log=" + logname;
            winscp.StartInfo.UseShellExecute = false;
            winscp.StartInfo.RedirectStandardInput = true;
            winscp.StartInfo.RedirectStandardOutput = true;
            winscp.StartInfo.CreateNoWindow = true;

            try
            {
                winscp.Start();
                lblconfirm.Text = "Status: WinSCP Started Successfully";
            }
            catch (Exception ex)
            {

                writeLog("from PutSFTP:  Could not run the WinSCP executable " + winscp.StartInfo.FileName + Environment.NewLine + ex.Message);
            }


            winscp.StandardInput.WriteLine("option batch abort");
            winscp.StandardInput.WriteLine("option confirm off");
            winscp.StandardInput.WriteLine("open sftp://" + username + ":" + password + "@" + remotehost);
            winscp.StandardInput.WriteLine("cd " + ini.IniReadValue("Download", "Remote Path"));
            winscp.StandardInput.WriteLine(@"get " + "/" + ini.IniReadValue("Download", "Remote Path") + "/*" + ini.IniReadValue("Download", "FileType") + " " + ini.IniReadValue("Download", "Local Path"));
            winscp.StandardInput.Close();

            string output = winscp.StandardOutput.ReadToEnd();
            lblconfirm.Text = "Download Success! Check logs for moe info";

            winscp.WaitForExit();
+1

SFTP.

0

IIS 7.x ( Windows Server 2008 Windows 7) FTPs, sFTP ( . ) - , sFTP.

sFTP , Microsoft . .NET wodSFTP.NET, sFTP-.

: wodSFTP.NET. - - .

, , Sourcecode #. SSH. ( ) # VB.NET.

( - www.weonlydo.com, #):

var wodSFTP1 = new WeOnlyDo.Client.SFTP();

// Authenticate with server using hostname, login, password.
wodSFTP1.Hostname = "your_hostname";
wodSFTP1.Login = "your_login";
wodSFTP1.Password = "your_password";
wodSFTP1.Blocking = True;  // Use synchronous connections
wodSFTP1.Connect();

wodSFTP1.GetFile("c:\", "/home/somepath/somefile.txt");

(). , - , , .

, , , , ( , , ).


Update: FTPs and sFTP are different protocols. Please follow the links for an explanation.

0
source

Since there is no built-in support, you can search on Google for other, commercial, components, just enter something like “.NET SFTP Components”

-1
source

Source: https://habr.com/ru/post/1743556/


All Articles