1. Open Visual studio and create a new website
2. Right Click to your solution and go to Manage Nuget Packages
3. Search for SSH.NET and install it
4. Include namespaces like using Renci.SshNet; and using System.IO;
5. On your Button Click Event write below code
string port = SFTP Port;
string host = SFTP Host;
string username = SFTP Username;
string password = SFTP Password;
string destinationFolder = SFTP Folder where the file will be uploaded;
using (SftpClient client = new SftpClient(host, Convert.ToInt32(port), username, password))
{
client.Connect();
client.ChangeDirectory(destinationFolder);
using (FileStream fs = new FileStream(path, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(path));
}
}
6. Run Your Project
2. Right Click to your solution and go to Manage Nuget Packages
3. Search for SSH.NET and install it
4. Include namespaces like using Renci.SshNet; and using System.IO;
5. On your Button Click Event write below code
string port = SFTP Port;
string host = SFTP Host;
string username = SFTP Username;
string password = SFTP Password;
string destinationFolder = SFTP Folder where the file will be uploaded;
using (SftpClient client = new SftpClient(host, Convert.ToInt32(port), username, password))
{
client.Connect();
client.ChangeDirectory(destinationFolder);
using (FileStream fs = new FileStream(path, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(path));
}
}
6. Run Your Project
No comments:
Post a Comment
Thanks