SFTP – Upload file

Below is a C# implementation to upload a file on SFTP:

using System;
using System.Collections.Generic;
using System.Text;
using Tamir.SharpSsh;

namespace Technical
{
    public class SFTPUploader
    {
        string host;
        string userName;
        string password;
        int port;

        public SFTPUploader(string Host, string UserName, string Password, int Port)
        {
            host = Host;
            userName = UserName;
            password = Password;
            port = Port;
        }

        public void UploadFile(string SourceFilePath, string DestinationPath)
        {
            Sftp scp = new Sftp(host, userName, password);
            scp.Connect(port);
            scp.Put(SourceFilePath, DestinationPath);
            scp.Close();
        }

        public void UploadFile(string[] SourceFilePaths, string DestinationPath)
        {
            Sftp scp = new Sftp(host, userName, password);
            scp.Connect(port);
            scp.Put(SourceFilePaths, DestinationPath);
            scp.Close();
        }
    }
}

*Note: The above implementation relies on Tamir.SharpSSH.dll”


The libraries can be downloaded from below references:

 

(Visited 80 times, 1 visits today)