<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
Filezilla分為client和server。其中FileZilla Server是Windows平臺下一個小巧的第三方FTP伺服器軟體,系統資源也佔用非常小,可以讓你快速簡單的建立自己的FTP伺服器。
開啟FileZilla,進行如下操作
下圖紅色區域就是linux系統的檔案目錄,可以直接把windows下的檔案直接拖拽進去。
跟FileZilla一樣,也是一款十分方便的檔案傳輸工具。WinSCP是連線Windows和Linux的。
https://winscp.net/eng/docs/library
// Setup session options SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = "example.com", UserName = "user", Password = "mypassword", SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...=" }; using (Session session = new Session()) { // Connect session.Open(sessionOptions); // Upload files TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; TransferOperationResult transferResult; transferResult = session.PutFiles(@"d:toupload*", "/home/user/", false, transferOptions); // Throw on any error transferResult.Check(); // Print results foreach (TransferEventArgs transfer in transferResult.Transfers) { Console.WriteLine("Upload of {0} succeeded", transfer.FileName); } }
FluentFTP是一款老外開發的基於.Net的支援FTP及的FTPS 的FTP類庫,FluentFTP是完全託管的FTP使用者端,被設計為易於使用和易於擴充套件。它支援檔案和目錄列表,上傳和下載檔案和SSL / TLS連線。
它底層由Socket實現,可以連線到Unix和Windows IIS建立FTP的伺服器,
github:https://github.com/robinrodricks/FluentFTP
// create an FTP client FtpClient client = new FtpClient("123.123.123.123"); // if you don't specify login credentials, we use the "anonymous" user account client.Credentials = new NetworkCredential("david", "pass123"); // begin connecting to the server client.Connect(); // get a list of files and directories in the "/htdocs" folder foreach (FtpListItem item in client.GetListing("/htdocs")) { // if this is a file if (item.Type == FtpFileSystemObjectType.File){ // get the file size long size = client.GetFileSize(item.FullName); } // get modified date/time of the file or folder DateTime time = client.GetModifiedTime(item.FullName); // calculate a hash for the file on the server side (default algorithm) FtpHash hash = client.GetHash(item.FullName); } // upload a file client.UploadFile(@"C:MyVideo.mp4", "/htdocs/big.txt"); // rename the uploaded file client.Rename("/htdocs/big.txt", "/htdocs/big2.txt"); // download the file again client.DownloadFile(@"C:MyVideo_2.mp4", "/htdocs/big2.txt"); // delete the file client.DeleteFile("/htdocs/big2.txt"); // delete a folder recursively client.DeleteDirectory("/htdocs/extras/"); // check if a file exists if (client.FileExists("/htdocs/big2.txt")){ } // check if a folder exists if (client.DirectoryExists("/htdocs/extras/")){ } // upload a file and retry 3 times before giving up client.RetryAttempts = 3; client.UploadFile(@"C:MyVideo.mp4", "/htdocs/big.txt", FtpExists.Overwrite, false, FtpVerify.Retry); // disconnect! good bye! client.Disconnect();
public class FtpFileMetadata { public long FileLength { get; set; } public string MD5Hash { get; set; } public DateTime LastModifyTime { get; set; } } public class FtpHelper { private FtpClient _client = null; private string _host = "127.0.0.1"; private int _port = 21; private string _username = "Anonymous"; private string _password = ""; private string _workingDirectory = ""; public string WorkingDirectory { get { return _workingDirectory; } } public FtpHelper(string host, int port, string username, string password) { _host = host; _port = port; _username = username; _password = password; } public Stream GetStream(string remotePath) { Open(); return _client.OpenRead(remotePath); } public void Get(string localPath, string remotePath) { Open(); _client.DownloadFile(localPath, remotePath, true); } public void Upload(Stream s, string remotePath) { Open(); _client.Upload(s, remotePath, FtpExists.Overwrite, true); } public void Upload(string localFile, string remotePath) { Open(); using (FileStream fileStream = new FileStream(localFile, FileMode.Open)) { _client.Upload(fileStream, remotePath, FtpExists.Overwrite, true); } } public int UploadFiles(IEnumerable<string> localFiles, string remoteDir) { Open(); List<FileInfo> files = new List<FileInfo>(); foreach (var lf in localFiles) { files.Add(new FileInfo(lf)); } int count = _client.UploadFiles(files, remoteDir, FtpExists.Overwrite, true, FtpVerify.Retry); return count; } public void MkDir(string dirName) { Open(); _client.CreateDirectory(dirName); } public bool FileExists(string remotePath) { Open(); return _client.FileExists(remotePath); } public bool DirExists(string remoteDir) { Open(); return _client.DirectoryExists(remoteDir); } public FtpListItem[] List(string remoteDir) { Open(); var f = _client.GetListing(); FtpListItem[] listItems = _client.GetListing(remoteDir); return listItems; } public FtpFileMetadata Metadata(string remotePath) { Open(); long size = _client.GetFileSize(remotePath); DateTime lastModifyTime = _client.GetModifiedTime(remotePath); return new FtpFileMetadata() { FileLength = size, LastModifyTime = lastModifyTime }; } public bool TestConnection() { return _client.IsConnected; } public void SetWorkingDirectory(string remoteBaseDir) { Open(); if (!DirExists(remoteBaseDir)) MkDir(remoteBaseDir); _client.SetWorkingDirectory(remoteBaseDir); _workingDirectory = remoteBaseDir; } private void Open() { if (_client == null) { _client = new FtpClient(_host, new System.Net.NetworkCredential(_username, _password)); _client.Port = 21; _client.RetryAttempts = 3; if (!string.IsNullOrWhiteSpace(_workingDirectory)) { _client.SetWorkingDirectory(_workingDirectory); } } } }
到此這篇關於C#呼叫第三方工具完成FTP操作的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45