Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 0 additions & 32 deletions src/Renci.SshNet/Abstractions/FileSystemAbstraction.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>Renci.SshNet</AssemblyName>
<AssemblyOriginatorKeyFile>../Renci.SshNet.snk</AssemblyOriginatorKeyFile>
<LangVersion>6</LangVersion>
<LangVersion>7.3</LangVersion>
<SignAssembly>true</SignAssembly>
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
Expand All @@ -19,6 +19,6 @@
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' ">
<DefineConstants>FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP</DefineConstants>
<DefineConstants>FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP</DefineConstants>
</PropertyGroup>
</Project>
88 changes: 48 additions & 40 deletions src/Renci.SshNet/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,60 +2074,68 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,

var sourceDirectory = new DirectoryInfo(sourcePath);

var sourceFiles = FileSystemAbstraction.EnumerateFiles(sourceDirectory, searchPattern).ToList();
if (sourceFiles.Count == 0)
return uploadedFiles;

#region Existing Files at The Destination

var destFiles = InternalListDirectory(destinationPath, null);
var destDict = new Dictionary<string, ISftpFile>();
foreach (var destFile in destFiles)
using (var sourceFiles = sourceDirectory.EnumerateFiles(searchPattern).GetEnumerator())
{
if (destFile.IsDirectory)
continue;
destDict.Add(destFile.Name, destFile);
}
if(!sourceFiles.MoveNext())
return uploadedFiles;

#endregion

#region Upload the difference

const Flags uploadFlag = Flags.Write | Flags.Truncate | Flags.CreateNewOrOpen;
foreach (var localFile in sourceFiles)
{
var isDifferent = !destDict.ContainsKey(localFile.Name);
#region Existing Files at The Destination

if (!isDifferent)
var destFiles = InternalListDirectory(destinationPath, null);
var destDict = new Dictionary<string, ISftpFile>();
foreach (var destFile in destFiles)
{
var temp = destDict[localFile.Name];
// TODO: Use md5 to detect a difference
//ltang: File exists at the destination => Using filesize to detect the difference
isDifferent = localFile.Length != temp.Length;
if (destFile.IsDirectory)
continue;
destDict.Add(destFile.Name, destFile);
}

if (isDifferent)
#endregion

#region Upload the difference

const Flags uploadFlag = Flags.Write | Flags.Truncate | Flags.CreateNewOrOpen;
do
{
var remoteFileName = string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", destinationPath, localFile.Name);
try
var localFile = sourceFiles.Current;
if (localFile == null)
{
continue;
}

var isDifferent = !destDict.ContainsKey(localFile.Name);

if (!isDifferent)
{
using (var file = File.OpenRead(localFile.FullName))
var temp = destDict[localFile.Name];
// TODO: Use md5 to detect a difference
//ltang: File exists at the destination => Using filesize to detect the difference
isDifferent = localFile.Length != temp.Length;
}

if (isDifferent)
{
var remoteFileName = string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", destinationPath, localFile.Name);
try
{
InternalUploadFile(file, remoteFileName, uploadFlag, null, null);
}
using (var file = File.OpenRead(localFile.FullName))
{
InternalUploadFile(file, remoteFileName, uploadFlag, null, null);
}

uploadedFiles.Add(localFile);
uploadedFiles.Add(localFile);

if (asynchResult != null)
if (asynchResult != null)
{
asynchResult.Update(uploadedFiles.Count);
}
}
catch (Exception ex)
{
asynchResult.Update(uploadedFiles.Count);
throw new Exception(string.Format("Failed to upload {0} to {1}", localFile.FullName, remoteFileName), ex);
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Failed to upload {0} to {1}", localFile.FullName, remoteFileName), ex);
}
}
} while (sourceFiles.MoveNext());
}

#endregion
Expand Down