diff --git a/.gitignore b/.gitignore index 592e974..1a21554 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ dotnet/dotnetframework/GeneXusFtps/bin/ dotnet/dotnetframework/GeneXusFtps/packages.config dotnet/dotnetcore/GeneXusFtpsNetCore/obj/ dotnet/resources/key.snk +dotnet/dotnetcore/GeneXusFtpsNetCore/bin/ diff --git a/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs b/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs index ec7c6f9..931d022 100644 --- a/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs +++ b/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs @@ -138,77 +138,78 @@ public override bool Put(String localPath, String remoteDir) } } - FileStream stream = null; try { - stream = File.OpenRead(local_path); - } - catch (Exception e) - { - this.error.setError("SF011", e.Message); - return false; - } - - string rDir = ""; - bool control = false; - string dirRemote = this.channel.WorkingDirectory; - - try - { - control = this.channel.WorkingDirectory.Contains("/"); - - } - catch (Exception e) - { - this.error.setError("SF018", e.Message); - return false; - } - if (control) - { - remoteDir = $"/{remoteDir.Replace(@"\", "/")}"; - rDir = SecurityUtils.compareStrings(remoteDir, "/") ? remoteDir : remoteDir + "/"; - } - else - { - rDir = SecurityUtils.compareStrings(remoteDir, "\\") ? remoteDir : remoteDir + "\\"; - } - rDir += GetFileNamne(localPath); - if (rDir.Length > 1) - { - if (rDir.StartsWith("\\") || rDir.StartsWith("/")) + using (FileStream stream = File.OpenRead(local_path)) { - rDir = rDir.Substring(1, rDir.Length - 1); - } - } + string rDir = ""; + bool control = false; + string dirRemote = this.channel.WorkingDirectory; - try - { - this.channel.UploadFile(stream, rDir, true, null); - } - catch (Exception e) - { - if (SecurityUtils.compareStrings(remoteDir, "/") || SecurityUtils.compareStrings(remoteDir, "\\") || SecurityUtils.compareStrings(remoteDir, "//")) - { try { - this.channel.UploadFile(stream, GetFileNamne(localPath), true, null); + control = this.channel.WorkingDirectory.Contains("/"); + } - catch (Exception s) + catch (Exception e) { - this.error.setError("SF012", s.Message); + this.error.setError("SF018", e.Message); return false; } - } - else - { - this.error.setError("SF013", e.Message); - return false; - } + if (control) + { + remoteDir = $"/{remoteDir.Replace(@"\", "/")}"; + rDir = SecurityUtils.compareStrings(remoteDir, "/") ? remoteDir : remoteDir + "/"; + } + else + { + rDir = SecurityUtils.compareStrings(remoteDir, "\\") ? remoteDir : remoteDir + "\\"; + } + rDir += GetFileNamne(localPath); + if (rDir.Length > 1) + { + if (rDir.StartsWith("\\") || rDir.StartsWith("/")) + { + rDir = rDir.Substring(1, rDir.Length - 1); + } + } + + try + { + this.channel.UploadFile(stream, rDir, true, null); + } + catch (Exception e) + { + if (SecurityUtils.compareStrings(remoteDir, "/") || SecurityUtils.compareStrings(remoteDir, "\\") || SecurityUtils.compareStrings(remoteDir, "//")) + { + try + { + this.channel.UploadFile(stream, GetFileNamne(localPath), true, null); + } + catch (Exception s) + { + this.error.setError("SF012", s.Message); + return false; + } + } + else + { + this.error.setError("SF013", e.Message); + return false; + } + } + + return true; + } } - return true; + catch (Exception e) + { + this.error.setError("SF011", e.Message); + return false; + } } @@ -253,12 +254,13 @@ public override bool Get(String remoteFilePath, String localDir) } try { + using (Stream file = new FileStream(localDir + GetFileNamne(remoteFilePath), FileMode.Create)) + { + //Stream file = new FileStream(localDir + GetFileNamne(remoteFilePath), FileMode.Create); + this.channel.DownloadFile(rDir, file); - Stream file = new FileStream(localDir + GetFileNamne(remoteFilePath), FileMode.Create); - this.channel.DownloadFile(rDir, file); - - + } } catch (Exception e) {