// 连接SFTP public SFtpClient connSftp(Server server) { SFtpClient ftp = new SFtpClient(server.Ip, server.SftpPort, server.OsUser, server.OsPassword); ftp.Connect(); return(ftp); }
public void SFtpClientTest() { SFtpClient ftp = new SFtpClient("127.0.0.1", 22, "root", "123456"); ftp.Connect(); List <FtpFile> files = ftp.getFileList("/"); Console.WriteLine("file count:" + files.ToArray().Length); foreach (FtpFile f in files) { Console.WriteLine(f.fullname); } }
public void SFtpClientTestDownload() { SFtpClient ftp = new SFtpClient("127.0.0.1", 22, "root", "123456"); ftp.Connect(); List <FtpFile> files = ftp.getFileList("/logs/"); Console.WriteLine("file count:" + files.ToArray().Length); foreach (FtpFile f in files) { Console.WriteLine(f.fullname); if (!f.isDirectory) { DownloadAsyncResult result = new DownloadAsyncResult(1, 1); AsyncCallback callback = new AsyncCallback(DownloadCallBack); ftp.DownloadFile(f.fullname, "E:\\" + f.name, callback); Console.WriteLine("download completeed!"); } } }