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?
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?