retrieve a list of files/dirs on sftp server

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
baech
Posts: 10
Joined: Thu 25 Aug 2016 09:30

retrieve a list of files/dirs on sftp server

Post by baech » Thu 25 Aug 2016 09:39

Hi, I am currently using the trial to create SFTP upload/download functionality, but I am stuck for now.

I have created a test to check the connection to the server, which is fine and it works, but now i need functionality to browse the root of the server for files and folders with the click of a button.

I am totally lost in this matter, any help would be appreciated. Here is a snippet of my codeL:

Code: Select all

 
oSFTPClient.SSHClient := oSSHClient;
oSFTPClient.Initialize;
oSFTPClient.ReadDirectory(oSFTPClient.OpenDirectory('\'));
what to do next?

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

Re: retrieve a list of files/dirs on sftp server

Post by ViktorV » Thu 25 Aug 2016 11:32

To solve your issue, you should use the TScSFTPClient.OnDirectoryList event handler.
You can get the needed information about using TScSFTPClient.OnDirectoryList event handlers in our documentation: https://www.devart.com/sbridge/docs/tsc ... rylist.htm and using our SFTPClient demo project.
You can find the SFTPClient project in the %SecureBridgeDemos%\SFTPClient directory. %SecureBridgeDemos% is the SecureBridge Demo projects installation path on your computer.

baech
Posts: 10
Joined: Thu 25 Aug 2016 09:30

Re: retrieve a list of files/dirs on sftp server

Post by baech » Thu 25 Aug 2016 11:44

ViktorV wrote:To solve your issue, you should use the TScSFTPClient.OnDirectoryList event handler.
You can get the needed information about using TScSFTPClient.OnDirectoryList event handlers in our documentation: https://www.devart.com/sbridge/docs/tsc ... rylist.htm and using our SFTPClient demo project.
You can find the SFTPClient project in the %SecureBridgeDemos%\SFTPClient directory. %SecureBridgeDemos% is the SecureBridge Demo projects installation path on your computer.
Would it be possible to browse the server with an explorer like window to select a file, I am a bit at a loss here, The OnDirectoryList needs the same handle as sent to the ReadDirectory ?

Excuse my stupidity, but I don't get how to retrieve a list in the root directory, and how to use the ReadDirectory method properly, since it doesn't seem the return anything.

Code: Select all

oSFTPClient.SSHClient := oSSHClient;
oSFTPClient.
while not oSFTPClient.EOF do
begin
  ReadDirectory(oSFTPClient.OpenDirectory('\'));
end;

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

Re: retrieve a list of files/dirs on sftp server

Post by ViktorV » Thu 25 Aug 2016 12:39

The OnDirectoryList event is raised on execution of the TScSFTPClient.ReadDirectory method.
The correct code for using the TScSFTPClient.ReadDirectory method is provided below:

Code: Select all

var
  Handle: TScSFTPFileHandle;
...
  oSFTPClient.SSHClient := oSSHClient;
  oSFTPClient.Initialize;
  Handle := oSFTPClient.OpenDirectory('\');
  try
    while not oSFTPClient.EOF do
      oSFTPClient.ReadDirectory(Handle);
  finally
    oSFTPClient.CloseHandle(Handle);
  end;
As we wrote earlier, you can learn how to use the TScSFTPClient.OnDirectoryList event handler and the TScSFTPClient.ReadDirectory method to solve the issue using our SFTPClient demo project.

baech
Posts: 10
Joined: Thu 25 Aug 2016 09:30

Re: retrieve a list of files/dirs on sftp server

Post by baech » Thu 25 Aug 2016 13:53

Alright, I give up, I simply can't find that demo project

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

Re: retrieve a list of files/dirs on sftp server

Post by ViktorV » Thu 25 Aug 2016 14:20

You can find the SFTPClient project in the %SecureBridgeDemos%\Demos\SFTPClient directory. %SecureBridgeDemos% is the SecureBridge Demo projects installation path on your computer.
Path to SecureBridge Demos is set during installation, on the "Select Destination Location" step of the SecureBridge installation wizard.

Post Reply