Home Forums .NET libraries Xceed SFTP/FTP for .NET How do I keep file timestamps when using MoveTo()

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20923 |

    I need to access a FTP folder and move files in the folder to another folder. When I use the code below, the date/timestamps of the files change to the current date and time. I need to retain the original timestamps. How can I do this?

    FtpConnection ftpConn =
    new FtpConnection(this.host, this.userID, this.passWD);

    FtpFile orig = new FtpFile(ftpConn, “somefolder/SDC”);
    FtpFile dest = new FtpFile(ftpConn, “somefolder/SDC/notified”);

    orig.MoveTo(dest, true);
    ——————————————————–

    Since the MoveTo() method returns a FileSystemItem, would the following replace my last line of code?

    Xceed.FileSystem.FileSystemItem fsi = orig.MoveTo(dest, true);
    fsi.ApplyPropertiesTo(fsi);

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Chris (had 2833 views)

    User (Old forums)
    Member
    Post count: 23064

    When uploading a file to an FTP server, the server creates a new file and writes the bytes it receives in the file. Therefore the LastAccessDateTime, LastWriteDateTime, CreationDateTime will not reflect the original local file DateTime. When moving files from one directory to another on the server, what actually happens is that the file is downloaded locally and uploaded again to the server, thus creating a new file (FTP servers do not support moving files between directories directly on the server, and this is a limitation of the FTP protocol and not of our library).

    However, there are new commands that are now available in the FTP protocol (called MF commands) that permits to change the different file times if, of course, your server supports those commands. Unfortunately, you will not be able to use the FtpConnection/FileSystem classes to do this, you will need to use the FtpClient class.

    You can use the GetRawExtendedFeatures() method to know if the server supports the MFMT and MFCT commands, and if so, use the SendCustomCommand method to send these commands to the server so you can set the file DateTime as required.

    Here is more information on these commands from the <a href=” http://www.ietf.org/internet-drafts/draft-somers-ftp-mfxx-03.txt”>RFC</a&gt;

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 3420 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.