private void Form1_Load(object sender, EventArgs e)
{
String Host = "sftp...";
//int Port = 88;
//String RemoteFileName = "TheDataFile.txt";
//String LocalDestinationFilename = "TheDataFile.txt";
String Username = "login";
String Password = "password";
using (SftpClient sftp = new SftpClient(Host, 88, Username, Password))
{
try
{
sftp.Connect();
if (sftp.IsConnected) //bağlantı başarılı ise buraya giriyor...
{
label1.Text = "connection successful.";
}
else
{
label1.Text = "connection unsuccessful!";
}
}
catch
{
label1.Text = "error!";
}
}
//serverdan dosyaları indirmek için yazdığım kod
string remotePath = "sftp://login**/0001.7z";
string localPath = "\"C:\\Users\\Halis\\Desktop\\indirdiğim\"";
string host = "sftp...";
string username = "login name";
string password = "password";
//
using (WebClient sftpClient = new WebClient())
{
sftpClient.Credentials = new NetworkCredential(username, password);
try
{
string sftpServer = "sftp...";
string remoteFilePath = "sftp:/login**//0001.7z";
string localFilePath = "\"C:\\Users\\Halis\\Desktop\\indirdiğim\"";
sftpClient.DownloadFile($"{sftpServer}/{remoteFilePath}", localFilePath);
Console.WriteLine("Dosya indirildi.");
}
catch (WebException ex)
{
Console.WriteLine($"Hata: {ex.Message}");
}
}
}
}
}
我想下载它,但我无法下载。我是否需要表单应用程序才能连接,或者是否需要添加按钮才能连接?我很困惑。 请帮助我