@@ -2110,14 +2110,17 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,
2110
2110
const Flags uploadFlag = Flags . Write | Flags . Truncate | Flags . CreateNewOrOpen ;
2111
2111
foreach ( var localFile in sourceFiles )
2112
2112
{
2113
+ // Clear the milliseconds from the timestamp, as that granularity will not carry over the wire with SFTP
2114
+ var lastWriteTimeUtc = ClearMilliseconds ( localFile . LastWriteTimeUtc ) ;
2113
2115
var isDifferent = ! destDict . ContainsKey ( localFile . Name ) ;
2114
2116
2115
2117
if ( ! isDifferent )
2116
2118
{
2117
2119
var temp = destDict [ localFile . Name ] ;
2118
2120
// TODO: Use md5 to detect a difference
2119
2121
//ltang: File exists at the destination => Using filesize to detect the difference
2120
- isDifferent = localFile . Length != temp . Length ;
2122
+ //kendallb: Use file length and timestamp to detect the difference
2123
+ isDifferent = localFile . Length != temp . Length || lastWriteTimeUtc != localFile . LastWriteTimeUtc ;
2121
2124
}
2122
2125
2123
2126
if ( isDifferent )
@@ -2128,6 +2131,11 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,
2128
2131
using ( var file = File . OpenRead ( localFile . FullName ) )
2129
2132
{
2130
2133
InternalUploadFile ( file , remoteFileName , uploadFlag , null , null ) ;
2134
+
2135
+ // Set the timestamp to match on the uploaded file (the helper function is not implemented in the library)
2136
+ var fileAttributes = GetAttributes ( remoteFileName ) ;
2137
+ fileAttributes . LastWriteTimeUtc = lastWriteTimeUtc ;
2138
+ SetAttributes ( remoteFileName , fileAttributes ) ;
2131
2139
}
2132
2140
2133
2141
uploadedFiles . Add ( localFile ) ;
@@ -2149,6 +2157,17 @@ private IEnumerable<FileInfo> InternalSynchronizeDirectories(string sourcePath,
2149
2157
return uploadedFiles ;
2150
2158
}
2151
2159
2160
+ /// <summary>
2161
+ /// Utility function to clear the millisecond value for a DateTime stamp
2162
+ /// </summary>
2163
+ /// <param name="date">Date to adjust</param>
2164
+ /// <returns>Adjusted DateTime value</returns>
2165
+ private static DateTime ClearMilliseconds (
2166
+ DateTime date )
2167
+ {
2168
+ return new DateTime ( date . Year , date . Month , date . Day , date . Hour , date . Minute , date . Second , date . Kind ) ;
2169
+ }
2170
+
2152
2171
#endregion
2153
2172
2154
2173
/// <summary>
0 commit comments