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{
//base._Ready(); //base._Ready();
//TestCode(); //TestCode();
this.EGEnabledProtocolTool<EGSsh>(); // this.EGEnabledProtocolTool<EGSsh>();
this.EGEnabledProtocolTool<EGTCPClient>(); // this.EGEnabledProtocolTool<EGTCPClient>();
this.EGEnabledProtocolTool<EGTCPServer>(); // this.EGEnabledProtocolTool<EGTCPServer>();
this.EGOnMessage<EasyMessage>(); // this.EGOnMessage<EasyMessage>();
// this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{ // // this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{
// }); // // });
//TestSsh(); // //TestSsh();
//TestTCPSend(); // //TestTCPSend();
TestTCPServer(); // 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(){ public async void TestSsh(){

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

@ -130,7 +130,7 @@ namespace EGFramework{
ResultFileList.Add(new WebDavFileMsg{ ResultFileList.Add(new WebDavFileMsg{
FileName = res.DisplayName , FileName = res.DisplayName ,
IsCollection = res.IsCollection , IsCollection = res.IsCollection ,
ContentLength = res.ContentLength , Size = res.ContentLength ,
Uri = res.Uri , Uri = res.Uri ,
LastUpdateTime = res.LastModifiedDate LastUpdateTime = res.LastModifiedDate
}); });
@ -155,7 +155,7 @@ namespace EGFramework{
CurrentFileList.Add(new WebDavFileMsg{ CurrentFileList.Add(new WebDavFileMsg{
FileName = res.DisplayName , FileName = res.DisplayName ,
IsCollection = res.IsCollection , IsCollection = res.IsCollection ,
ContentLength = res.ContentLength , Size = res.ContentLength ,
Uri = res.Uri , Uri = res.Uri ,
LastUpdateTime = res.LastModifiedDate LastUpdateTime = res.LastModifiedDate
}); });
@ -209,18 +209,18 @@ namespace EGFramework{
/// <summary> /// <summary>
/// unit is kb /// unit is kb
/// </summary> /// </summary>
public long? ContentLength { set; get; } public long? Size { set; get; }
public string Uri { set; get; } public string Uri { set; get; }
public DateTime? LastUpdateTime { set; get; } public DateTime? LastUpdateTime { set; get; }
public DateTime? LastModify { 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.FileName = fileName;
this.IsCollection = isCollection; this.IsCollection = isCollection;
this.Uri = uri; this.Uri = uri;
this.ContentLength = contentLength; this.Size = size;
this.LastModify = lastModify; this.LastModify = lastModify;
} }
} }

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

@ -1,12 +1,19 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using FluentFTP;
namespace EGFramework{ namespace EGFramework{
public class EGFtpSave : IEGSave, IEGSaveFile 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) public void CopyFile(string sourcePath, string copyPath)
@ -34,14 +41,19 @@ namespace EGFramework{
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public IEnumerable<IEGFileMsg> ListLocalFilePath(string localPath) public IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath)
{ {
throw new System.NotImplementedException(); FTPClient.Connect();
} FtpListItem[] nameList = FTPClient.GetListing(remotePath);
List<IEGFileMsg> fileList = new List<IEGFileMsg>();
public IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath) foreach (var item in nameList)
{ {
throw new System.NotImplementedException(); 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) public void MakeDirectory(string remotePath)
@ -61,7 +73,9 @@ namespace EGFramework{
public void SyncFile(string remotePath, string localPath) 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) public void UploadFile(FileStream localFileStream, string remotePath)
@ -71,7 +85,9 @@ namespace EGFramework{
public void UploadFile(string localPath, string remotePath) 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
/// <summary> /// <summary>
/// unit is kb /// unit is kb
/// </summary> /// </summary>
public long? ContentLength { get; } public long? Size { get; }
public string Uri { get; } public string Uri { get; }
public DateTime? LastModify { 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{ public interface IEGSaveFileReadOnly{
IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath); IEnumerable<IEGFileMsg> ListRemoteFilePath(string remotePath);
IEnumerable<IEGFileMsg> ListLocalFilePath(string localPath);
bool IsRemoteFileExist(string remotePath); bool IsRemoteFileExist(string remotePath);
bool IsRemoteDirectoryExist(string remotePath); bool IsRemoteDirectoryExist(string remotePath);
void DownloadFile(string remotePath,string localPath); void DownloadFile(string remotePath,string localPath);

Loading…
Cancel
Save