Getting RemoteFileInfo.LastWriteTime is incorrect

Advertisement

sramsay
Joined:
Posts:
2
Location:
Roseville, CA

Getting RemoteFileInfo.LastWriteTime is incorrect

Hi,

I'm trying to manually synchronize files based on last modified time using C# code. However the LastWriteTime I'm getting from the remote file seems to be off by 1 hr. For example, the remote file was modified '12/8/2010 12:00:00 AM' and the local file was modified '12/7/2010 11:00:00 PM'. I've tried using SessionOptions.AddRawSettings to adjust it but it's not yielding any differences.

Here's my code:

------------------------
public void Main()
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "ftp.x.org",
UserName = "anonymous",
Password = ""
};

sessionOptions.AddRawSettings("PreserveTime", "0");
sessionOptions.AddRawSettings("ConsiderDST", "1");

string remotePath = "/";
string localPath = "c:\\temp\\";
DateTime remoteWriteTime;
DateTime localWriteTime;

using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);

RemoteDirectoryInfo directory = session.ListDirectory(remotePath);
foreach (RemoteFileInfo fileInfo in directory.Files)
{
string remoteFilePath = remotePath + fileInfo.Name;
string localFilePath = localPath + fileInfo.Name;

// Check if the remote file exists locally
if (File.Exists(localFilePath))
{
remoteWriteTime = fileInfo.LastWriteTime;
localWriteTime = File.GetLastWriteTime(localFilePath);

if (remoteWriteTime > localWriteTime)
{
session.GetFiles(remoteFilePath, localFilePath, false, null).Check();

------------------------

Any ideas?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Re: Getting RemoteFileInfo.LastWriteTime is incorrect

I'm not sure what the problem is.
1) The remote file has actually a different timestamp than you get from RemoteFileInfo.LastWriteTime.
2) The file was uploaded by WinSCP and the remote timestamp does not match the timestamp of source local file.

Reply with quote

sramsay
Joined:
Posts:
2
Location:
Roseville, CA

Re: Getting RemoteFileInfo.LastWriteTime is incorrect

martin wrote:

I'm not sure what the problem is.
1) The remote file has actually a different timestamp than you get from RemoteFileInfo.LastWriteTime.
2) The file was uploaded by WinSCP and the remote timestamp does not match the timestamp of source local file.

Thanks for the reply.

#1 is correct, #2 is not the case.

Reply with quote

Advertisement

You can post new topics in this forum