private void bt_ftp_Click(object sender, EventArgs e)
{
try
{
引用WinSCP类
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "ftp域名",
PortNumber = 21,// SFTP默认端口22
UserName = "用户名",
Password = "密码"
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
// remove:bool,成功后是否删除本地文件,默认false
var transferResult = session.PutFiles(@"D:\123456\*", "/", false, transferOptions);//upload
transferResult = session.GetFiles("/*", "D:\\123456789\\", true, transferOptions);//download
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Failures)
{
Console.WriteLine("DownLoad of {0} Error!", transfer.FileName);
}
MessageBox.Show("FTP信息处理成功!");
}
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex);
}
}
标签:transferResult,FTP,false,C#,上传下载,transferOptions,session,new
From: https://www.cnblogs.com/xynmw/p/18332335