Browse Source

fixed ftp any method

master
jkpete 4 months ago
parent
commit
5049d7ebcd
  1. 29
      Example/UsingTest/Script/EGSaveTest.cs
  2. 10
      addons/EGFramework/Module/OtherTools/EGWebDav.cs
  3. 38
      addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs
  4. 19
      addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

29
Example/UsingTest/Script/EGSaveTest.cs

@ -17,16 +17,25 @@ namespace EGFramework.Examples.Test{ @@ -17,16 +17,25 @@ namespace EGFramework.Examples.Test{
//base._Ready();
//TestCode();
this.EGEnabledProtocolTool<EGSsh>();
this.EGEnabledProtocolTool<EGTCPClient>();
this.EGEnabledProtocolTool<EGTCPServer>();
this.EGOnMessage<EasyMessage>();
// this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{
// });
//TestSsh();
//TestTCPSend();
TestTCPServer();
// this.EGEnabledProtocolTool<EGSsh>();
// this.EGEnabledProtocolTool<EGTCPClient>();
// this.EGEnabledProtocolTool<EGTCPServer>();
// this.EGOnMessage<EasyMessage>();
// // this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{
// // });
// //TestSsh();
// //TestTCPSend();
// TestTCPServer();
TestFTP();
}
public void TestFTP(){
EGFtpSave ftp = new EGFtpSave();
ftp.InitSave("127.0.0.1");
IEnumerable<IEGFileMsg> msgs = ftp.ListRemoteFilePath("/App/");
foreach(IEGFileMsg msg in msgs){
GD.Print(msg.FileName+" | "+msg.IsCollection+" | "+msg.Size+"kb | "+msg.LastModify);
}
}
public async void TestSsh(){

10
addons/EGFramework/Module/OtherTools/EGWebDav.cs

@ -130,7 +130,7 @@ namespace EGFramework{ @@ -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{ @@ -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{ @@ -209,18 +209,18 @@ namespace EGFramework{
/// <summary>
/// unit is kb
/// </summary>
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;
}
}

38
addons/EGFramework/Module/SaveTools/File/EGFtpSave.cs

@ -1,12 +1,19 @@ @@ -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{ @@ -34,14 +41,19 @@ namespace EGFramework{
throw new System.NotImplementedException();
}
public IEnumerable<IEGFileMsg> ListLocalFilePath(string localPath)
public IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath)
{
throw new System.NotImplementedException();
}
public IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath)
{
throw new System.NotImplementedException();
FTPClient.Connect();
FtpListItem[] nameList = FTPClient.GetListing(remotePath);
List<IEGFileMsg> fileList = new List<IEGFileMsg>();
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{ @@ -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{ @@ -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();
}
}
}

19
addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

@ -97,14 +97,27 @@ namespace EGFramework @@ -97,14 +97,27 @@ namespace EGFramework
/// <summary>
/// unit is kb
/// </summary>
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<IEGFileMsg> ListRemoteFilePath(string remotePath);
IEnumerable<IEGFileMsg> ListLocalFilePath(string localPath);
bool IsRemoteFileExist(string remotePath);
bool IsRemoteDirectoryExist(string remotePath);
void DownloadFile(string remotePath,string localPath);

Loading…
Cancel
Save