Skip to content

Commit 4a031e0

Browse files
authored
Merge pull request #288 from sshnet/issue286
ScpClient: Upload of file should fail if remote path exists as directory
2 parents 2d840aa + 84f3a28 commit 4a031e0

File tree

12 files changed

+169
-95
lines changed

12 files changed

+169
-95
lines changed

src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
198198
<Link>Common\PortForwardEventArgs.cs</Link>
199199
</Compile>
200+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
201+
<Link>Common\PosixPath.cs</Link>
202+
</Compile>
200203
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
201204
<Link>Common\ProxyException.cs</Link>
202205
</Compile>
@@ -953,7 +956,7 @@
953956
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
954957
<ProjectExtensions>
955958
<VisualStudio>
956-
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
959+
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
957960
</VisualStudio>
958961
</ProjectExtensions>
959962
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet.Silverlight/Renci.SshNet.Silverlight.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
210210
<Link>Common\PortForwardEventArgs.cs</Link>
211211
</Compile>
212+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
213+
<Link>Common\PosixPath.cs</Link>
214+
</Compile>
212215
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
213216
<Link>Common\ProxyException.cs</Link>
214217
</Compile>
@@ -946,7 +949,7 @@
946949
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
947950
<SilverlightProjectProperties />
948951
</FlavorProperties>
949-
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
952+
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
950953
</VisualStudio>
951954
</ProjectExtensions>
952955
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@
218218
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
219219
<Link>Common\PortForwardEventArgs.cs</Link>
220220
</Compile>
221+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
222+
<Link>Common\PosixPath.cs</Link>
223+
</Compile>
221224
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
222225
<Link>Common\ProxyException.cs</Link>
223226
</Compile>
@@ -952,7 +955,7 @@
952955
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
953956
<SilverlightProjectProperties />
954957
</FlavorProperties>
955-
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
958+
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
956959
</VisualStudio>
957960
</ProjectExtensions>
958961
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void Arrange()
4848
_fileName = CreateTemporaryFile(new byte[] {1});
4949
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
5050
_fileInfo = new FileInfo(_fileName);
51-
_path = random.Next().ToString(CultureInfo.InvariantCulture);
51+
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
5252
_quotedPath = _path.ShellQuote();
5353
_uploadingRegister = new List<ScpUploadEventArgs>();
5454

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void SetupData()
5656
_fileName = CreateTemporaryFile(_fileContent);
5757
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
5858
_fileInfo = new FileInfo(_fileName);
59-
_path = random.Next().ToString(CultureInfo.InvariantCulture);
59+
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
6060
_quotedPath = _path.ShellQuote();
6161
_uploadingRegister = new List<ScpUploadEventArgs>();
6262
}
@@ -86,11 +86,7 @@ private void SetupMocks()
8686
_pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
8787
_channelSessionMock.InSequence(sequence)
8888
.Setup(p => p.SendData(It.Is<byte[]>(b => b.SequenceEqual(CreateData(
89-
string.Format("C0644 {0} {1}\n",
90-
_fileInfo.Length,
91-
Path.GetFileName(_fileName)
92-
)
93-
)))));
89+
string.Format("C0644 {0} {1}\n", _fileInfo.Length, string.Empty))))));
9490
_pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
9591
_channelSessionMock.InSequence(sequence)
9692
.Setup(

src/Renci.SshNet.UAP10/Renci.SshNet.UAP10.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
259259
<Link>Common\PortForwardEventArgs.cs</Link>
260260
</Compile>
261+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
262+
<Link>Common\PosixPath.cs</Link>
263+
</Compile>
261264
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
262265
<Link>Common\ProxyException.cs</Link>
263266
</Compile>

src/Renci.SshNet.WindowsPhone/Renci.SshNet.WindowsPhone.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@
200200
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
201201
<Link>Common\PortForwardEventArgs.cs</Link>
202202
</Compile>
203+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
204+
<Link>Common\PosixPath.cs</Link>
205+
</Compile>
203206
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
204207
<Link>Common\ProxyException.cs</Link>
205208
</Compile>

src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@
241241
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
242242
<Link>Common\PortForwardEventArgs.cs</Link>
243243
</Compile>
244+
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
245+
<Link>Common\PosixPath.cs</Link>
246+
</Compile>
244247
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
245248
<Link>Common\ProxyException.cs</Link>
246249
</Compile>
@@ -979,7 +982,7 @@
979982
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
980983
<ProjectExtensions>
981984
<VisualStudio>
982-
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
985+
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
983986
</VisualStudio>
984987
</ProjectExtensions>
985988
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet/Common/PosixPath.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Renci.SshNet.Common
2+
{
3+
internal class PosixPath
4+
{
5+
/// <summary>
6+
/// Gets the file name part of a given POSIX path.
7+
/// </summary>
8+
/// <param name="path">The POSIX path to get the file name for.</param>
9+
/// <returns>
10+
/// The file name part of <paramref name="path"/>.
11+
/// </returns>
12+
/// <remarks>
13+
/// If <paramref name="path"/> contains no forward slash or has a trailing
14+
/// forward slash, then <paramref name="path"/> is returned.
15+
/// </remarks>
16+
public static string GetFileName(string path)
17+
{
18+
var pathEnd = path.LastIndexOf('/');
19+
if (pathEnd == -1 || pathEnd == path.Length - 1)
20+
return path;
21+
return path.Substring(pathEnd + 1);
22+
}
23+
}
24+
}

src/Renci.SshNet/Renci.SshNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Common\ChannelRequestEventArgs.cs" />
9898
<Compile Include="Common\CountdownEvent.cs" />
9999
<Compile Include="Common\Pack.cs" />
100+
<Compile Include="Common\PosixPath.cs" />
100101
<Compile Include="Common\ProxyException.cs">
101102
<SubType>Code</SubType>
102103
</Compile>

0 commit comments

Comments
 (0)