Preserve timestamp in SMTP

0

How to preserve timestamp while downloading file from UNIX server?

 

i.e. if my file date-time on UNIX server is 01 Mar 2014 10:56PM

And if download the file on 10 Mar 2014 at 03:45 PM then file date-time will get changed to 10 Mar 2014 03:45 PM.

edited 11/16/2017 12:41:36 AM
asked 3/19/2014 2:30:08 PM
add a comment

6 Answers

0

You can use the following code snippet to sync last write time of the remote files:

[code lang='c#']

// Create a new class instance.
Sftp client = new Sftp();
 
// Connect to the SFTP server.
client.Connect("demo.componentpro.com");
 
// Authenticate.
client.Authenticate("test", "test");
 
// ...
 
// Upload *.cs and *.vb files that smaller than 50kb from local folder 'c:\myfolder2' to remote folder '/myfolder2'.
TransferOptions opt = new TransferOptions();
client.RestoreFileProperties = true;
client.ServerTimeZoneOffset = client.GetServerTimeDifference();
 
// You can use this:
client.Upload("D:\\temp\\Test\\*.hxk", "/myfolder2", opt);
 
// ...
 
// Disconnect.
client.Disconnect();[/code]
 
answered 11/16/2017 12:41:36 AM
add a comment
0

We understand your issue. For the version 5.3 we would suggest using the Progress event to set the LastWriteTime when the state is FileDownloaded. You can get the lastwritetime of the file in the event data object.

In the v6.0 that we will release in April, there is an option that helps you do so.

 
answered 11/16/2017 12:41:36 AM
add a comment
0

Thanks for early reply. Will try your suggestion.

 
answered 11/16/2017 12:41:36 AM
add a comment
0

It's SFTP and not SMTP?

I apologies for typo mistake.

 
answered 11/16/2017 12:41:36 AM
add a comment
0

As per your suggestion, I added one line in switch case of public void Progress(object sender, FileSystemProgressEventArgs e) function

 

case TransferState.FileUploaded:

      client.SetLastWriteTime(e.DestinationPath, e.SourceFileInfo.LastWriteTime);

 

case TransferState.FileDownloaded:

      File.SetLastWriteTime(e.DestinationPath, e.SourceFileInfo.LastWriteTime);

 

And it worked, thank you for your support.

 
answered 11/16/2017 12:41:36 AM
add a comment
0

We are also facing same kind of issue. While doing replication using componentpro sftp connection, the time difference between PR and DR is exactly 5 hrs 30 mins. that is difference between UTC and IST. how to resolve the issue?

thank you

Regards,

Uma Mehavarnan

 
answered 11/16/2017 12:41:36 AM
add a comment

Your Answer

Not the answer you're looking for? Browse other questions tagged smtp or ask your own question.