DownloadFile, UploadFile and OnDirectoryList

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
happylalala
Posts: 3
Joined: Thu 14 Nov 2019 04:33

DownloadFile, UploadFile and OnDirectoryList

Post by happylalala » Fri 20 Dec 2019 03:32

Hi all,
We need to download files in a listed directory. I have a couple of questions regarding the callback event OnDirectoryList of TScSFTPClient as well as the TScSFTPClient.DownloadFile, UploadFile methods

1) Is it a good practice to download every single file by calling the SFTPClient.DownloadFile in the callback OnDirectoryList or we should save all files into a list first. Then iterate through the file list and call the DownloadFile?

2) The FileInfo: TScSFTPFileInfo returned from the callback, is it always assigned? Am I correct to do the following to check whether the returned FileInfo it is a file:
[code] if not Assigned(FileInfo) or (FileInfo.Attributes.FileType <> ftFile) then begin
Exit;
end;[/code]

3) With the DownloadFile(Source) and UploadFile(Destination), which operating system path types should I pass in DOS(\Server\Doc\file.txt or UNIX(/Server/Doc/file.txt)? Or Does the components support both DOS and Unix path separators?

Thank you,
Tran

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

Re: DownloadFile, UploadFile and OnDirectoryList

Post by ViktorV » Fri 20 Dec 2019 15:06

1. To solve the defined task, it's more convenient to save file names to a list and then download the files using the list.
2. Yes, your code is correct and should solve the defined task.
3. Most SFTP servers use the Unix format, however, there may be exceptions.

happylalala
Posts: 3
Joined: Thu 14 Nov 2019 04:33

Re: DownloadFile, UploadFile and OnDirectoryList

Post by happylalala » Sun 22 Dec 2019 22:42

Hi ViktorV,

Thanks for your response.

I just need a bit more details for question 3. What do you recommend for the path? When the request hit the server, does the SFTPClient component automatically handle the conversions for path separators from DOS to UNIX or vice-versa? Or should I specify the path type according to the server's specification, eg: if the server path is in UNIX then I should use UNIX.

Regards,
Tran

tcaduto12068
Posts: 143
Joined: Wed 17 Aug 2016 05:57

Re: DownloadFile, UploadFile and OnDirectoryList

Post by tcaduto12068 » Mon 23 Dec 2019 13:46

Always use forward slashes and you will be fine.
Windows does not care if the slashes are / or \

i.e. this would work just fine on windows:
c:\myfolder\12/20/2019

I have used such paths with the force directories function and it creates the path just fine even with the different slashes.

happylalala
Posts: 3
Joined: Thu 14 Nov 2019 04:33

Re: DownloadFile, UploadFile and OnDirectoryList

Post by happylalala » Tue 24 Dec 2019 00:13

Thanks for your reply tcaduto12068. I will just force the UNIX path.

Cheers

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

Re: DownloadFile, UploadFile and OnDirectoryList

Post by ViktorV » Fri 27 Dec 2019 07:56

As tcaduto12068 said, Windows does not care if the slashes are / or \, so you can try using the Unix format.

Post Reply