Topic "Getting RemoteFileInfo.LastWriteTime is incorrect"

Author Message
sramsay
[View user's profile]

Joined: 2012-09-05
Posts: 2
Location: Roseville, CA
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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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.
_________________
Martin Prikryl
sramsay
[View user's profile]

Joined: 2012-09-05
Posts: 2
Location: Roseville, CA
prikryl 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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Have you seen this FAQ?
https://winscp.net/eng/docs/timestamp#windows
Does it help?
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License