Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

sramsay

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.
martin

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.
sramsay

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?