I have created code for uploading file to SFTP remote server, But it shows error as
"The given path's format is not supported."
i have given my code and sample details. Iam sure path which iam giving is incorrect, Kindly rectify me.
my dll for SFTP is:
using Renci.SshNet;
using Renci.SshNet.Sftp;
sample data:
server: 192.168.1.1
remotemachine(fileZilla LocalPath):"C:\Program Files\JSCAPE MFT Server\users\hind\scope"
public Form1()
{
InitializeComponent();
source = @"E:\To_Upload\tests_example.xls";
destination = "sftp://scope@hind/" + @" C:\Program Files\JSCAPE MFT Server\users\hind\scope";
host = "hind";
username = "scope";
password = "S@ssw0rd987";
port = 22;
UploadSFTPFile(host, username, password, source, destination, port);
}
public static void UploadSFTPFile(string host, string username, string password, string sourcefile, string destinationpath, int port)
{
try
{
using (SftpClient client = new SftpClient(host, port, username, password))
{
client.Connect();
client.ChangeDirectory(destinationpath);
using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "UploadSFTPFile");
}
}
Kindly rectify my problem. and how to pass SFTP path in destination
What I have tried:
public Form1()
{
InitializeComponent();
source = @"E:\To_Upload\tests_example.xls";
destination = "sftp://scope@hind/" + @" C:\Program Files\JSCAPE MFT Server\users\hind\scope";
host = "hind";
username = "scope";
password = "S@ssw0rd987";
port = 22;
UploadSFTPFile(host, username, password, source, destination, port);
}
public static void UploadSFTPFile(string host, string username, string password, string sourcefile, string destinationpath, int port)
{
try
{
using (SftpClient client = new SftpClient(host, port, username, password))
{
client.Connect();
client.ChangeDirectory(destinationpath);
using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "UploadSFTPFile");
}
}