SetAttributes not working as it should

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
HBL
Posts: 3
Joined: Wed 24 Oct 2018 06:04

SetAttributes not working as it should

Post by HBL » Wed 24 Oct 2018 07:02

Hey

Im using your component to etablish a connection to a SFTP (Bulletproff FTP) and its wokring fine. But when I try to change the Create, Access and modified time of a file on the SFTP its not working.

I use the newest Secure Bridge 8.2 on Delphi XE5

After I have connected to the SFTP I try to run the following code in order to change any of the above datetime

Code: Select all

procedure TForm1.Button6Click(Sender: TObject);
var
  CreateTime, AccessTime, ModifiedTime: TDatetime;
  FTPCon: ThblFTPConnection;
begin
  FTPCon := ThblFTPConnection.Create;
  Try
    CreateTime := EncodeDateTime(2018, 1, 1, 08,08,08, 0);
    AccessTime := EncodeDateTime(2018, 3, 3, 12,12,12, 0);
    ModifiedTime := EncodeDateTime(2018, 6, 6, 16,16,16, 0);
    FTPCon.SetAttributes('/test/2018-01-15_panelists.txt', CreateTime, AccessTime, ModifiedTime);
  Finally
    FTPCon.Free;
  end;
end;

procedure ThblFTPConnection.SetAttributes(const RemotePathFile: String;
  const CreateTime, AccessTime, ModifiedTime: TDatetime);
var
  Attrs: TScSFTPFileAttributes;
begin
  if not Connected then
    Connect;
    
  Attrs := TScSFTPFileAttributes.Create;
  Try
    if CompareDateTime(AccessTime, MinDateTime) <> 0 then Begin
      Attrs.AccessTime := AccessTime;
      Attrs.ValidAttributes := Attrs.ValidAttributes + [aAccessTime];
    end;

    if CompareDateTime(ModifiedTime, MinDateTime) <> 0 then Begin
      Attrs.ModifyTime := ModifiedTime;
      Attrs.ValidAttributes := Attrs.ValidAttributes + [aModifyTime];
    end;    

    if CompareDateTime(CreateTime, MinDateTime) <> 0 then Begin
      Attrs.CreateTime := CreateTime;
      Attrs.ValidAttributes := Attrs.ValidAttributes + [aCreateTime];
    end;

    FSFTPClient.SetAttributes(RemotePathFile, Attrs);


    //Trying to read back what we just set and show it in a message.
    FSFTPClient.RetrieveAttributes(Attrs, RemotePathFile, False, [aCreateTime, aAccessTime, aModifyTime]);

    Showmessage('Set Access Date: ' + DateTimeToStr(AccessTime) + sLineBreak +
                'Set Modifed Date: ' + DateTimeToStr(ModifiedTime) + sLineBreak +
                'Set Create Date: ' + DateTimeToStr(CreateTime) + sLineBreak + sLineBreak +
                'Get Access Date: ' + DateTimeToStr(Attrs.AccessTime) + sLineBreak +
                'Get Modified Date: ' + DateTimeToStr(Attrs.ModifyTime) + sLineBreak +
                'Get Create Date: ' + DateTimeToStr(Attrs.CreateTime) + sLineBreak);
  Finally
    Attrs.Free;
  end;
end;

The problem here is that only my CreateTime is set, the Access and Modified time dosnt change and the OnSuccess Event fire with the following operations, I dont get any OnError Event message, so everything should be working.

My Own message, but the opSettingFileAttrs is the Operation: TScSFTPOperation Enum as string.
Success: opSettingFileAttrs - System File: /test/2018-01-15_panelists.txt
Success: opClosingHandle - System File: /test/2018-01-15_panelists.txt


Is this because the SetAttributes command is not supported by the SFTP Server (Bulletproff) or Im I doing something wrong in my code ?

ViktorV
Devart Team
Posts: 2495
Joined: Wed 30 Jul 2014 07:16

Re: SetAttributes not working as it should

Post by ViktorV » Thu 25 Oct 2018 13:41

During the investigation, we found out that this behavior is related to the work of BulletProof FTP, not of SecureBrige. When the TScSFTPClient1.SetAttributes method is executed, none of the attributes on the server is being changed, but along with this, the server does not return any error. Thus, please forward this issue to the BulletProof FTP developers. Please note that the SFTP protocol version should be 4 or higher since lower versions do not return the CreateTime value. So in your example, CreateTime equals the value you set, not the value the server returned. To retrieve more precise file attributes from the server, you need to set the TScSFTPClient.Version properties in vSFTP4 or higher. Alternatively, you net make the following changes to your example:

Code: Select all

    Attrs.CreateTime := 0;
    Attrs.ModifyTime := 0;
    Attrs.AccessTime := 0;
    ScSFTPClient1.RetrieveAttributes(Attrs, RemotePathFile, False, [aCreateTime, aAccessTime, aModifyTime]);

Post Reply