From b5da22861fb49abd8235ce2671b2d2ccac586fe7 Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Mon, 21 Apr 2025 12:07:36 +0800 Subject: [PATCH] fixed host from Josn --- .../Module/SaveTools/File/EGSftpSave.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/EGFramework/Module/SaveTools/File/EGSftpSave.cs b/addons/EGFramework/Module/SaveTools/File/EGSftpSave.cs index 6c997e5..aedbc27 100644 --- a/addons/EGFramework/Module/SaveTools/File/EGSftpSave.cs +++ b/addons/EGFramework/Module/SaveTools/File/EGSftpSave.cs @@ -1,12 +1,32 @@ using System.Collections.Generic; using System.IO; +using Newtonsoft.Json; +using Renci.SshNet; namespace EGFramework{ + public struct EGSftpHost + { + public string Host { set; get; } + public string User { set; get; } + public string Password { set; get; } + public int Port { set; get; } + } public class EGSftpSave : IEGSave,IEGSaveFile { - public void InitSave(string path) + public SftpClient Sftp { set; get; } + + /// + /// Host is a json string, such as {"Host":"","User":"","Password":"","Port":22} + /// + /// + public void InitSave(string hostJson) { - throw new System.NotImplementedException(); + EGSftpHost host = JsonConvert.DeserializeObject(hostJson); + if(host.Port == 0){ + host.Port = 22; + } + this.Sftp = new SftpClient(host.Host, host.Port, host.User, host.Password); + // this.Sftp = new SftpClient(path); } public void CopyFile(string sourcePath, string copyPath)