Unable to delete remote file with SFTP

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
opal
Posts: 3
Joined: Fri 02 Sep 2011 13:01

Unable to delete remote file with SFTP

Post by opal » Fri 02 Sep 2011 13:19

dear all

we encountered a problem when using SecureBridge 3.0 (the licensed version, not the demo version) with Delphi XE ond Windows 7 professional 64bit.
we tried to delete a remote file using the method TScSFTPClient.RemoveFile. If the file is located directly in the serverroot directory, deleting works. However, if the file is placed in a subdirectory (e.g. [SERVERROOT]/subdir/testfile.txt), we get a "EScSFTPError" exception with the message "SFTP server error occured: Permission denied".
the user has all permissions for the server root directory, the subdirectory and the file to be deleted.
by the way, we have the same problem with the method TScSFTPClient.DownloadFile

the same method call worked with Windows XP, SecureBridge 2.6 and Delphi 2006.

is this a known problem? can you give us any advice?

thanks steve

opal
Posts: 3
Joined: Fri 02 Sep 2011 13:01

Update

Post by opal » Mon 05 Sep 2011 13:25

We have further analysed the situation.
The "permission denied" error occurs only if the OpenDirectory procedure is called before the RemoveFile method. If the OpenDirectory call is removed, then the RemoveFile method succeeds.
The following piece of code illustrates the problem. When commenting out the line 27 and 28 (see comments), the file "foo.bar" is deleted on the remote server.
As already stated, the procedure DownloadFile shows the same behaviour.

Greets Steve

Code: Select all

procedure MyClass.ScSSHClientServerKeyValidate_(Sender: TObject; NewServerKey: TScKey; var Accept: Boolean);
begin
  Accept := True;
end;


procedure MyClass.sampleMethod;
var
  ScSSHClient: TScSSHClient;
  ScFileStorage: TScFileStorage;
  ScSFTPClient: TScSFTPClient;
  remoteDirFileHandle: TScSFTPFileHandle;
begin
  ScFileStorage := TScFileStorage.Create(nil);
  ScSSHClient := TScSSHClient.Create(nil);
  ScSSHClient.KeyStorage := ScFileStorage;
  ScSSHClient.OnServerKeyValidate := ScSSHClientServerKeyValidate_;
  ScSSHClient.HostName := '192.168.9.33';
  ScSSHClient.User := 'myUser';
  ScSSHClient.Password := 'myPass';
  ScSSHClient.Connect;

  ScSFTPClient := TScSFTPClient.Create(nil);
  ScSFTPClient.SSHClient := ScSSHClient;
  ScSFTPClient.Initialize;

  remoteDirFileHandle := ScSFTPClient.OpenDirectory('./subdir'); // line 27
  ScSFTPClient.CloseHandle(remoteDirFileHandle);                 // line 28

  ScSFTPClient.RemoveFile('./subdir/foo.bar');

  ScSFTPClient.Disconnect;

end;

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 05 Sep 2011 14:11

I cannot reproduce the problem.
The problem seems to arise with a specific SFTP server. Please specify the exact version of your SFTP server.
Besides, try using any other SFTP server and check that the problem persists.

opal
Posts: 3
Joined: Fri 02 Sep 2011 13:01

Post by opal » Mon 05 Sep 2011 17:19

Hi Dimon

Thanks for your answer.
First, we tried freeFTPd.
We successfully tested the code now with another SFTP server (copssh).

Greets Steve

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 06 Sep 2011 07:14

If there is anything else I can help you with, please contact me.

Post Reply