Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
124 changes: 63 additions & 61 deletions dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

Expand Down Expand Up @@ -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)
{
Expand Down