mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-29 15:11:12 +08:00
1. Compare the specified local directory and destination directory.
2. Upload the difference from the local directory to destination directory.
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
<AssemblyName>Renci.SshNet</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -744,6 +748,9 @@
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpSession.cs">
|
||||
<Link>Sftp\SftpSession.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpSynchronizeDirectoriesAsyncResult.cs">
|
||||
<Link>Sftp\SftpSynchronizeDirectoriesAsyncResult.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpUploadAsyncResult.cs">
|
||||
<Link>Sftp\SftpUploadAsyncResult.cs</Link>
|
||||
</Compile>
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
<SilverlightApplication>false</SilverlightApplication>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<!-- This property group is only here to support building this project using the
|
||||
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
|
||||
@@ -707,6 +711,9 @@
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpSession.cs">
|
||||
<Link>Sftp\SftpSession.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpSynchronizeDirectoriesAsyncResult.cs">
|
||||
<Link>Sftp\SftpSynchronizeDirectoriesAsyncResult.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet\Sftp\SftpUploadAsyncResult.cs">
|
||||
<Link>Sftp\SftpUploadAsyncResult.cs</Link>
|
||||
</Compile>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.237
|
||||
// Runtime Version:4.0.30319.17929
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Tests.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to oleg-centos.edc.renci.org.
|
||||
/// Looks up a localized string similar to 127.0.0.1.
|
||||
/// </summary>
|
||||
internal static string HOST {
|
||||
get {
|
||||
|
||||
@@ -112,10 +112,10 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DSA_KEY_WITHOUT_PASS" xml:space="preserve">
|
||||
<value>-----BEGIN DSA PRIVATE KEY-----
|
||||
@@ -149,7 +149,7 @@ D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM
|
||||
-----END DSA PRIVATE KEY-----</value>
|
||||
</data>
|
||||
<data name="HOST" xml:space="preserve">
|
||||
<value>oleg-centos.edc.renci.org</value>
|
||||
<value>127.0.0.1</value>
|
||||
</data>
|
||||
<data name="INVALID_KEY" xml:space="preserve">
|
||||
<value>-----BEGIN DSA PRIVATE KEY-----
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile />
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -97,6 +101,9 @@
|
||||
<Compile Include="..\Renci.SshNet.Tests\SftpClientTests\SftpFileTest.cs">
|
||||
<Link>SftpClientTests\SftpFileTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet.Tests\SftpClientTests\SynchronizeDirectoriesTest.cs">
|
||||
<Link>SftpClientTests\SynchronizeDirectoriesTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Renci.SshNet.Tests\SftpClientTests\UploadDownloadFileTest.cs">
|
||||
<Link>SftpClientTests\UploadDownloadFileTest.cs</Link>
|
||||
</Compile>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.261
|
||||
// Runtime Version:4.0.30319.17929
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Tests.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to oleg-centos.edc.renci.org.
|
||||
/// Looks up a localized string similar to 127.0.0.1.
|
||||
/// </summary>
|
||||
internal static string HOST {
|
||||
get {
|
||||
@@ -141,7 +141,7 @@ namespace Renci.SshNet.Tests.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org.
|
||||
/// Looks up a localized string similar to 127.0.0.1.
|
||||
/// </summary>
|
||||
internal static string PROXY_HOST {
|
||||
get {
|
||||
|
||||
@@ -149,7 +149,7 @@ D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM
|
||||
-----END DSA PRIVATE KEY-----</value>
|
||||
</data>
|
||||
<data name="HOST" xml:space="preserve">
|
||||
<value>oleg-centos.edc.renci.org</value>
|
||||
<value>127.0.0.1</value>
|
||||
</data>
|
||||
<data name="INVALID_KEY" xml:space="preserve">
|
||||
<value>-----BEGIN DSA PRIVATE KEY-----
|
||||
@@ -172,7 +172,7 @@ tM7dZpB+reWl9L5e2L8=
|
||||
<value>22</value>
|
||||
</data>
|
||||
<data name="PROXY_HOST" xml:space="preserve">
|
||||
<value>proxy.oleg-centos.edc.renci.org</value>
|
||||
<value>127.0.0.1</value>
|
||||
</data>
|
||||
<data name="PROXY_PORT" xml:space="preserve">
|
||||
<value>8123</value>
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -77,12 +81,12 @@
|
||||
<Compile Include="SftpClientTests\DeleteDirectoryTest.cs" />
|
||||
<Compile Include="SftpClientTests\DeleteFileTest.cs" />
|
||||
<Compile Include="SftpClientTests\GetTest.cs" />
|
||||
<Compile Include="SftpClientTests\GlobalScapeSftpServerTest.cs" />
|
||||
<Compile Include="SftpClientTests\ListDirectoryTest.cs" />
|
||||
<Compile Include="SftpClientTests\ProxyTest.cs" />
|
||||
<Compile Include="SftpClientTests\RenameFileTest.cs" />
|
||||
<Compile Include="SftpClientTests\SftpFileStreamTest.cs" />
|
||||
<Compile Include="SftpClientTests\SftpFileTest.cs" />
|
||||
<Compile Include="SftpClientTests\SynchronizeDirectoriesTest.cs" />
|
||||
<Compile Include="SftpClientTests\UploadDownloadFileTest.cs" />
|
||||
<Compile Include="SshClientTests\ProxyTest.cs" />
|
||||
<Compile Include="SshClientTests\TestPortForwarding.NET40.cs" />
|
||||
@@ -102,6 +106,7 @@
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Renci.SshNet.Tests.SftpClientTests
|
||||
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
client.Connect();
|
||||
client.RunCommand("rm -rf *");
|
||||
//client.RunCommand("rm -rf *");
|
||||
client.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Properties;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Tests.SftpClientTests
|
||||
{
|
||||
[TestClass]
|
||||
public class SynchronizeDirectoriesTest
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_SynchronizeDirectories()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
|
||||
string sourceDir = Path.GetDirectoryName(uploadedFileName);
|
||||
string destDir = "/";
|
||||
string searchPattern = Path.GetFileName(uploadedFileName);
|
||||
var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);
|
||||
|
||||
Assert.IsTrue(upLoadedFiles.Count() > 0);
|
||||
|
||||
foreach (var file in upLoadedFiles)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Sftp")]
|
||||
public void Test_Sftp_BeginSynchronizeDirectories()
|
||||
{
|
||||
using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
|
||||
{
|
||||
sftp.Connect();
|
||||
|
||||
string uploadedFileName = Path.GetTempFileName();
|
||||
|
||||
string sourceDir = Path.GetDirectoryName(uploadedFileName);
|
||||
string destDir = "/";
|
||||
string searchPattern = Path.GetFileName(uploadedFileName);
|
||||
|
||||
var asyncResult = sftp.BeginSynchronizeDirectories(sourceDir,
|
||||
destDir,
|
||||
searchPattern,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
// Wait for the WaitHandle to become signaled.
|
||||
asyncResult.AsyncWaitHandle.WaitOne(1000);
|
||||
|
||||
var upLoadedFiles = sftp.EndSynchronizeDirectories(asyncResult);
|
||||
|
||||
Assert.IsTrue(upLoadedFiles.Count() > 0);
|
||||
|
||||
foreach (var file in upLoadedFiles)
|
||||
{
|
||||
Debug.WriteLine(file.FullName);
|
||||
}
|
||||
|
||||
// Close the wait handle.
|
||||
asyncResult.AsyncWaitHandle.Close();
|
||||
|
||||
sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@
|
||||
<SilverlightApplication>false</SilverlightApplication>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -752,7 +756,7 @@
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.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.
|
||||
|
||||
@@ -12,8 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Tests", "Renci.SshNet.Tests\Renci.SshNet.Tests.csproj", "{C45379B9-17B1-4E89-BC2E-6D41726413E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{EFAF2072-A01F-4970-878A-AAD40326AFD2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Silverlight", "Renci.SshNet.Silverlight\Renci.SshNet.Silverlight.csproj", "{77C294BB-1DC2-49DC-BE16-963F8F22794D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.NET35", "Renci.SshNet.NET35\Renci.SshNet.NET35.csproj", "{DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}"
|
||||
@@ -22,9 +20,31 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Tests.NET35",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.WindowsPhone", "Renci.SshNet.WindowsPhone\Renci.SshNet.WindowsPhone.csproj", "{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zlib DLL", "Zlib\Zlib DLL.csproj", "{9816BA86-9250-4C00-A912-25F07F8677D1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(TeamFoundationVersionControl) = preSolution
|
||||
SccNumberOfProjects = 7
|
||||
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
|
||||
SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs11
|
||||
SccLocalPath0 = .
|
||||
SccProjectUniqueName1 = Renci.SshNet\\Renci.SshNet.csproj
|
||||
SccProjectName1 = Renci.SshNet
|
||||
SccLocalPath1 = Renci.SshNet
|
||||
SccProjectUniqueName2 = Renci.SshNet.Tests\\Renci.SshNet.Tests.csproj
|
||||
SccProjectName2 = Renci.SshNet.Tests
|
||||
SccLocalPath2 = Renci.SshNet.Tests
|
||||
SccProjectUniqueName3 = Renci.SshNet.Silverlight\\Renci.SshNet.Silverlight.csproj
|
||||
SccProjectName3 = Renci.SshNet.Silverlight
|
||||
SccLocalPath3 = Renci.SshNet.Silverlight
|
||||
SccProjectUniqueName4 = Renci.SshNet.NET35\\Renci.SshNet.NET35.csproj
|
||||
SccProjectName4 = Renci.SshNet.NET35
|
||||
SccLocalPath4 = Renci.SshNet.NET35
|
||||
SccProjectUniqueName5 = Renci.SshNet.Tests.NET35\\Renci.SshNet.Tests.NET35.csproj
|
||||
SccProjectName5 = Renci.SshNet.Tests.NET35
|
||||
SccLocalPath5 = Renci.SshNet.Tests.NET35
|
||||
SccProjectUniqueName6 = Renci.SshNet.WindowsPhone\\Renci.SshNet.WindowsPhone.csproj
|
||||
SccProjectName6 = Renci.SshNet.WindowsPhone
|
||||
SccLocalPath6 = Renci.SshNet.WindowsPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(TestCaseManagementSettings) = postSolution
|
||||
CategoryFile = Renci.SshNet1.vsmdi
|
||||
EndGlobalSection
|
||||
@@ -57,16 +77,6 @@ Global
|
||||
{C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|x86.Build.0 = Debug|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|x86.ActiveCfg = Release|x86
|
||||
{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|x86.Build.0 = Release|x86
|
||||
{77C294BB-1DC2-49DC-BE16-963F8F22794D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{77C294BB-1DC2-49DC-BE16-963F8F22794D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{77C294BB-1DC2-49DC-BE16-963F8F22794D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@@ -107,16 +117,6 @@ Global
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{3AD3EDF0-702E-4A91-8735-DCE4659AA54C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{9816BA86-9250-4C00-A912-25F07F8677D1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
<AssemblyName>Renci.SshNet</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -399,6 +403,7 @@
|
||||
<Compile Include="Sftp\SftpSession.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Sftp\SftpSynchronizeDirectoriesAsyncResult.cs" />
|
||||
<Compile Include="Sftp\SftpUploadAsyncResult.cs" />
|
||||
<Compile Include="Sftp\StatusCodes.cs">
|
||||
<SubType>Code</SubType>
|
||||
|
||||
@@ -183,7 +183,12 @@ namespace Renci.SshNet
|
||||
{
|
||||
get
|
||||
{
|
||||
return (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null) && !(this._socket.Poll(10, SelectMode.SelectRead));
|
||||
return (!this._isDisconnecting
|
||||
&& this._socket != null
|
||||
&& this._socket.Connected
|
||||
&& this._isAuthenticated
|
||||
&& this._messageListenerCompleted != null);
|
||||
//&& !(this._socket.Poll(10, SelectMode.SelectRead));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Renci.SshNet.Common;
|
||||
using System.IO;
|
||||
|
||||
namespace Renci.SshNet.Sftp
|
||||
{
|
||||
public class SftpSynchronizeDirectoriesAsyncResult : AsyncResult<IEnumerable<FileInfo>>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the number of files read so far.
|
||||
/// </summary>
|
||||
public int FilesRead { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SftpListDirectoryAsyncResult"/> class.
|
||||
/// </summary>
|
||||
/// <param name="asyncCallback">The async callback.</param>
|
||||
/// <param name="state">The state.</param>
|
||||
public SftpSynchronizeDirectoriesAsyncResult(AsyncCallback asyncCallback, Object state)
|
||||
: base(asyncCallback, state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates asynchronous operation status information.
|
||||
/// </summary>
|
||||
/// <param name="filesRead">The files read.</param>
|
||||
internal void Update(int filesRead)
|
||||
{
|
||||
this.FilesRead = filesRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,6 +346,141 @@ namespace Renci.SshNet
|
||||
return ar.EndInvoke();
|
||||
}
|
||||
|
||||
|
||||
#region SynchronizeDirectories
|
||||
#if (!WINDOWS_PHONE)
|
||||
public IEnumerable<FileInfo> SynchronizeDirectories(string sourceDir
|
||||
, string destDir
|
||||
, string searchPattern)
|
||||
{
|
||||
return InternalSynchronizeDirectories(sourceDir, destDir, searchPattern, null);
|
||||
}
|
||||
|
||||
public IAsyncResult BeginSynchronizeDirectories(string sourceDir
|
||||
, string destDir
|
||||
, string searchPattern, AsyncCallback asyncCallback, object state)
|
||||
{
|
||||
if (sourceDir == null)
|
||||
throw new ArgumentNullException("sourceDir");
|
||||
if (destDir.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("destDir");
|
||||
|
||||
// Ensure that connection is established.
|
||||
this.EnsureConnection();
|
||||
|
||||
var asyncResult = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state);
|
||||
|
||||
this.ExecuteThread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = this.InternalSynchronizeDirectories(sourceDir, destDir, searchPattern, asyncResult);
|
||||
|
||||
asyncResult.SetAsCompleted(result, false);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
asyncResult.SetAsCompleted(exp, false);
|
||||
}
|
||||
});
|
||||
|
||||
return asyncResult;
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> EndSynchronizeDirectories(IAsyncResult asyncResult)
|
||||
{
|
||||
var ar = asyncResult as SftpSynchronizeDirectoriesAsyncResult;
|
||||
|
||||
if (ar == null || ar.EndInvokeCalled)
|
||||
throw new ArgumentException("Either the IAsyncResult object did not come from the corresponding async method on this type, or EndExecute was called multiple times with the same IAsyncResult.");
|
||||
|
||||
// Wait for operation to complete, then return result or throw exception
|
||||
return ar.EndInvoke();
|
||||
}
|
||||
|
||||
private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourceDir,
|
||||
string destDir,
|
||||
string searchPattern,
|
||||
SftpSynchronizeDirectoriesAsyncResult asynchResult)
|
||||
{
|
||||
if (destDir.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("destDir");
|
||||
if (!Directory.Exists(sourceDir))
|
||||
throw new FileNotFoundException(string.Format("Source directory not found: {0}", sourceDir));
|
||||
|
||||
IList<FileInfo> uploadedFiles = new List<FileInfo>();
|
||||
|
||||
DirectoryInfo source = new DirectoryInfo(sourceDir);
|
||||
|
||||
#if (SILVERLIGHT)
|
||||
var sourceFiles = source.EnumerateFiles(searchPattern);
|
||||
#else
|
||||
var sourceFiles = source.GetFiles(searchPattern);
|
||||
#endif
|
||||
if (sourceFiles == null || sourceFiles.Count() <= 0)
|
||||
return uploadedFiles;
|
||||
|
||||
try
|
||||
{
|
||||
#region Existing Files at The Destination
|
||||
var destFiles = InternalListDirectory(destDir, null);
|
||||
Dictionary<string, SftpFile> destDict = new Dictionary<string, SftpFile>();
|
||||
foreach (var destFile in destFiles)
|
||||
{
|
||||
if (destFile.IsDirectory)
|
||||
continue;
|
||||
destDict.Add(destFile.Name, destFile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Upload the difference
|
||||
string remoteFileName;
|
||||
bool isDifferent = false;
|
||||
Flags uploadFlag = Flags.Write | Flags.Truncate | Flags.CreateNewOrOpen;
|
||||
foreach (var localFile in sourceFiles)
|
||||
{
|
||||
isDifferent = !destDict.ContainsKey(localFile.Name);
|
||||
if (!isDifferent)
|
||||
{
|
||||
SftpFile temp = destDict[localFile.Name];
|
||||
//ltang: File exists at the destination => Using filesize to detect the difference
|
||||
isDifferent = localFile.Length != temp.Length;
|
||||
}
|
||||
|
||||
if (isDifferent)
|
||||
{
|
||||
remoteFileName = string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", destDir, localFile.Name);
|
||||
try
|
||||
{
|
||||
using (var file = File.OpenRead(localFile.FullName))
|
||||
{
|
||||
InternalUploadFile(file, remoteFileName, null, uploadFlag);
|
||||
}
|
||||
uploadedFiles.Add(localFile);
|
||||
|
||||
if (asynchResult != null)
|
||||
{
|
||||
asynchResult.Update(uploadedFiles.Count);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("Failed to upload {0} to {1}", localFile.FullName, remoteFileName), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return uploadedFiles;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets reference to remote file or directory.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user