Page 1 of 1
retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 09:39
by baech
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?
Re: retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 11:32
by ViktorV
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.
Re: retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 11:44
by baech
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;
Re: retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 12:39
by ViktorV
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.
Re: retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 13:53
by baech
Alright, I give up, I simply can't find that demo project
Re: retrieve a list of files/dirs on sftp server
Posted: Thu 25 Aug 2016 14:20
by ViktorV
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.