Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit d6106e9

Browse files
authored
Fix put in folder (#56)
1 parent 0b12329 commit d6106e9

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public override bool Put(String localPath, String remoteDir)
130130
this.error.setError("SF005", "The channel is invalid, reconect");
131131
return false;
132132
}
133+
if (remoteDir.Length > 1)
134+
{
135+
if (remoteDir.StartsWith("\\") || remoteDir.StartsWith("/"))
136+
{
137+
remoteDir = remoteDir.Substring(1, remoteDir.Length - 1);
138+
}
139+
}
133140

134141
FileStream stream = null;
135142
try
@@ -147,34 +154,41 @@ public override bool Put(String localPath, String remoteDir)
147154
string dirRemote = this.channel.WorkingDirectory;
148155

149156
try
150-
{
157+
{
151158
control = this.channel.WorkingDirectory.Contains("/");
152159

153-
}catch(Exception e)
154-
{
160+
}
161+
catch (Exception e)
162+
{
155163
this.error.setError("SF018", e.Message);
156164
return false;
157-
}
165+
}
158166
if (control)
159167
{
160168
remoteDir = $"/{remoteDir.Replace(@"\", "/")}";
161-
rDir = SecurityUtils.compareStrings(dirRemote, "/") ? dirRemote : dirRemote + "/";
162-
//rDir += this.channel.WorkingDirectory + remoteDir + "/" + GetFileNamne(localPath);
169+
rDir = SecurityUtils.compareStrings(remoteDir, "/") ? remoteDir : remoteDir + "/";
163170
}
164171
else
165172
{
166-
rDir = SecurityUtils.compareStrings(dirRemote, "\\") ? dirRemote : dirRemote + "\\";
167-
// rDir = this.channel.WorkingDirectory + remoteDir + "\\" + GetFileNamne(localPath);
173+
rDir = SecurityUtils.compareStrings(remoteDir, "\\") ? remoteDir : remoteDir + "\\";
168174
}
169175
rDir += GetFileNamne(localPath);
176+
if (rDir.Length > 1)
177+
{
178+
if (rDir.StartsWith("\\") || rDir.StartsWith("/"))
179+
{
180+
rDir = rDir.Substring(1, rDir.Length - 1);
181+
}
182+
}
183+
170184
try
171185
{
172186
this.channel.UploadFile(stream, rDir, true, null);
173187
}
174188
catch (Exception e)
175189
{
176-
if(SecurityUtils.compareStrings(remoteDir, "/") || SecurityUtils.compareStrings(remoteDir, "\\"))
177-
{
190+
if (SecurityUtils.compareStrings(remoteDir, "/") || SecurityUtils.compareStrings(remoteDir, "\\") || SecurityUtils.compareStrings(remoteDir, "//"))
191+
{
178192
try
179193
{
180194
this.channel.UploadFile(stream, GetFileNamne(localPath), true, null);
@@ -184,9 +198,9 @@ public override bool Put(String localPath, String remoteDir)
184198
this.error.setError("SF012", s.Message);
185199
return false;
186200
}
187-
}
188-
else
189-
{
201+
}
202+
else
203+
{
190204
this.error.setError("SF013", e.Message);
191205
return false;
192206
}

0 commit comments

Comments
 (0)