Skip to content

Commit

Permalink
Merge pull request #288 from sshnet/issue286
Browse files Browse the repository at this point in the history
ScpClient: Upload of file should fail if remote path exists as directory
  • Loading branch information
drieseng authored Aug 27, 2017
2 parents 2d840aa + 84f3a28 commit 4a031e0
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 95 deletions.
5 changes: 4 additions & 1 deletion src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down Expand Up @@ -953,7 +956,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
5 changes: 4 additions & 1 deletion src/Renci.SshNet.Silverlight/Renci.SshNet.Silverlight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down Expand Up @@ -946,7 +949,7 @@
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
<SilverlightProjectProperties />
</FlavorProperties>
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down Expand Up @@ -952,7 +955,7 @@
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
<SilverlightProjectProperties />
</FlavorProperties>
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void Arrange()
_fileName = CreateTemporaryFile(new byte[] {1});
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
_fileInfo = new FileInfo(_fileName);
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
_quotedPath = _path.ShellQuote();
_uploadingRegister = new List<ScpUploadEventArgs>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void SetupData()
_fileName = CreateTemporaryFile(_fileContent);
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
_fileInfo = new FileInfo(_fileName);
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
_quotedPath = _path.ShellQuote();
_uploadingRegister = new List<ScpUploadEventArgs>();
}
Expand Down Expand Up @@ -86,11 +86,7 @@ private void SetupMocks()
_pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
_channelSessionMock.InSequence(sequence)
.Setup(p => p.SendData(It.Is<byte[]>(b => b.SequenceEqual(CreateData(
string.Format("C0644 {0} {1}\n",
_fileInfo.Length,
Path.GetFileName(_fileName)
)
)))));
string.Format("C0644 {0} {1}\n", _fileInfo.Length, string.Empty))))));
_pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
_channelSessionMock.InSequence(sequence)
.Setup(
Expand Down
3 changes: 3 additions & 0 deletions src/Renci.SshNet.UAP10/Renci.SshNet.UAP10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<Compile Include="..\Renci.SshNet\Common\PortForwardEventArgs.cs">
<Link>Common\PortForwardEventArgs.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\PosixPath.cs">
<Link>Common\PosixPath.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\Common\ProxyException.cs">
<Link>Common\ProxyException.cs</Link>
</Compile>
Expand Down Expand Up @@ -979,7 +982,7 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
24 changes: 24 additions & 0 deletions src/Renci.SshNet/Common/PosixPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Renci.SshNet.Common
{
internal class PosixPath
{
/// <summary>
/// Gets the file name part of a given POSIX path.
/// </summary>
/// <param name="path">The POSIX path to get the file name for.</param>
/// <returns>
/// The file name part of <paramref name="path"/>.
/// </returns>
/// <remarks>
/// If <paramref name="path"/> contains no forward slash or has a trailing
/// forward slash, then <paramref name="path"/> is returned.
/// </remarks>
public static string GetFileName(string path)
{
var pathEnd = path.LastIndexOf('/');
if (pathEnd == -1 || pathEnd == path.Length - 1)
return path;
return path.Substring(pathEnd + 1);
}
}
}
1 change: 1 addition & 0 deletions src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Common\ChannelRequestEventArgs.cs" />
<Compile Include="Common\CountdownEvent.cs" />
<Compile Include="Common\Pack.cs" />
<Compile Include="Common\PosixPath.cs" />
<Compile Include="Common\ProxyException.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
Loading

0 comments on commit 4a031e0

Please sign in to comment.