1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private void button2_Click(object sender, EventArgs e)
{
int Port = int.Parse(textBox2.Text);
string Host = textBox1.Text;
string Username = textBox3.Text;
string Password = textBox4.Text;
string WorkingDirectory = textBox6.Text;
string UploadDirectory = textBox5.Text;
FileInfo FI = new FileInfo(UploadDirectory);
string UploadFile = FI.FullName;
Console.WriteLine(FI.Name);
Console.WriteLine("UploadFile" + UploadFile);
var Client = new SftpClient(Host, Port, Username, Password);
Client.Connect();
if (Client.IsConnected)
{
var FS = new FileStream(UploadFile, FileMode.Open);
if (FS != null)
{
Client.UploadFile(FS, WorkingDirectory + FI.Name, null);
Client.Disconnect();
Client.Dispose();
MessageBox.Show("Envoyé avec succès", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
} |