diff --git a/Example/UsingTest/Script/EGSaveTest.cs b/Example/UsingTest/Script/EGSaveTest.cs index e56cb1c..71d5ade 100644 --- a/Example/UsingTest/Script/EGSaveTest.cs +++ b/Example/UsingTest/Script/EGSaveTest.cs @@ -17,16 +17,25 @@ namespace EGFramework.Examples.Test{ //base._Ready(); //TestCode(); - this.EGEnabledProtocolTool(); - this.EGEnabledProtocolTool(); - this.EGEnabledProtocolTool(); - this.EGOnMessage(); - // this.EGRegisterMessageEvent((e,sender)=>{ - - // }); - //TestSsh(); - //TestTCPSend(); - TestTCPServer(); + // this.EGEnabledProtocolTool(); + // this.EGEnabledProtocolTool(); + // this.EGEnabledProtocolTool(); + // this.EGOnMessage(); + // // this.EGRegisterMessageEvent((e,sender)=>{ + + // // }); + // //TestSsh(); + // //TestTCPSend(); + // TestTCPServer(); + TestFTP(); + } + public void TestFTP(){ + EGFtpSave ftp = new EGFtpSave(); + ftp.InitSave("127.0.0.1"); + IEnumerable msgs = ftp.ListRemoteFilePath("/App/"); + foreach(IEGFileMsg msg in msgs){ + GD.Print(msg.FileName+" | "+msg.IsCollection+" | "+msg.Size+"kb | "+msg.LastModify); + } } public async void TestSsh(){ diff --git a/addons/EGFramework/Module/OtherTools/EGWebDav.cs b/addons/EGFramework/Module/OtherTools/EGWebDav.cs index 4222347..185b00a 100644 --- a/addons/EGFramework/Module/OtherTools/EGWebDav.cs +++ b/addons/EGFramework/Module/OtherTools/EGWebDav.cs @@ -130,7 +130,7 @@ namespace EGFramework{ ResultFileList.Add(new WebDavFileMsg{ FileName = res.DisplayName , IsCollection = res.IsCollection , - ContentLength = res.ContentLength , + Size = res.ContentLength , Uri = res.Uri , LastUpdateTime = res.LastModifiedDate }); @@ -155,7 +155,7 @@ namespace EGFramework{ CurrentFileList.Add(new WebDavFileMsg{ FileName = res.DisplayName , IsCollection = res.IsCollection , - ContentLength = res.ContentLength , + Size = res.ContentLength , Uri = res.Uri , LastUpdateTime = res.LastModifiedDate }); @@ -209,18 +209,18 @@ namespace EGFramework{ /// /// unit is kb /// - public long? ContentLength { set; get; } + public long? Size { set; get; } public string Uri { set; get; } public DateTime? LastUpdateTime { set; get; } public DateTime? LastModify { set; get; } - public void Init(string fileName, bool isCollection, string uri, long? contentLength = null, DateTime? lastModify = null) + public void Init(string fileName, bool isCollection, string uri, long? size = null, DateTime? lastModify = null) { this.FileName = fileName; this.IsCollection = isCollection; this.Uri = uri; - this.ContentLength = contentLength; + this.Size = size; this.LastModify = lastModify; } } diff --git a/addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs b/addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs index c086e90..99d35c4 100644 --- a/addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs +++ b/addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs @@ -1,12 +1,19 @@ using System.Collections.Generic; using System.IO; +using FluentFTP; namespace EGFramework{ public class EGFtpSave : IEGSave, IEGSaveFile { - public void InitSave(string path) + public FtpClient FTPClient { set; get; } + + public void InitSave(string host) { - throw new System.NotImplementedException(); + this.FTPClient = new FtpClient(host); + } + public void InitUser(string user, string password) + { + this.FTPClient.Credentials = new System.Net.NetworkCredential(user, password); } public void CopyFile(string sourcePath, string copyPath) @@ -34,14 +41,19 @@ namespace EGFramework{ throw new System.NotImplementedException(); } - public IEnumerable ListLocalFilePath(string localPath) + public IEnumerable ListRemoteFilePath(string remotePath) { - throw new System.NotImplementedException(); - } - - public IEnumerable ListRemoteFilePath(string remotePath) - { - throw new System.NotImplementedException(); + FTPClient.Connect(); + FtpListItem[] nameList = FTPClient.GetListing(remotePath); + List fileList = new List(); + foreach (var item in nameList) + { + IEGFileMsg fileMsg = new EGFileMsg(); + fileMsg.Init(item.Name, item.Type == FtpObjectType.Directory, item.FullName, item.Size/1024, item.Modified); + fileList.Add(fileMsg); + } + FTPClient.Disconnect(); + return fileList; } public void MakeDirectory(string remotePath) @@ -61,7 +73,9 @@ namespace EGFramework{ public void SyncFile(string remotePath, string localPath) { - throw new System.NotImplementedException(); + FTPClient.Connect(); + FTPClient.DownloadFile(localPath, remotePath, FtpLocalExists.Overwrite); + FTPClient.Disconnect(); } public void UploadFile(FileStream localFileStream, string remotePath) @@ -71,7 +85,9 @@ namespace EGFramework{ public void UploadFile(string localPath, string remotePath) { - throw new System.NotImplementedException(); + FTPClient.Connect(); + FTPClient.UploadFile(localPath, remotePath, FtpRemoteExists.Overwrite, true, FtpVerify.Retry); + FTPClient.Disconnect(); } } } \ No newline at end of file diff --git a/addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs b/addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs index eaaa922..9cb5a1a 100644 --- a/addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs +++ b/addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs @@ -97,14 +97,27 @@ namespace EGFramework /// /// unit is kb /// - public long? ContentLength { get; } + public long? Size { get; } public string Uri { get; } public DateTime? LastModify { get; } - public void Init(string fileName,bool isCollection,string uri,long? contentLength,DateTime? lastmodify); + public void Init(string fileName,bool isCollection,string uri,long? size,DateTime? lastmodify); + } + public struct EGFileMsg : IEGFileMsg{ + public string FileName { get; set; } + public bool IsCollection { get; set; } + public long? Size { get; set; } + public string Uri { get; set; } + public DateTime? LastModify { get; set; } + public void Init(string fileName,bool isCollection,string uri,long? size,DateTime? lastmodify){ + this.FileName = fileName; + this.IsCollection = isCollection; + this.Uri = uri; + this.Size = size; + this.LastModify = lastmodify; + } } public interface IEGSaveFileReadOnly{ IEnumerable ListRemoteFilePath(string remotePath); - IEnumerable ListLocalFilePath(string localPath); bool IsRemoteFileExist(string remotePath); bool IsRemoteDirectoryExist(string remotePath); void DownloadFile(string remotePath,string localPath);