Page 1 of 1

DownloadFile, UploadFile and OnDirectoryList

Posted: Fri 20 Dec 2019 03:32
by happylalala
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

Re: DownloadFile, UploadFile and OnDirectoryList

Posted: Fri 20 Dec 2019 15:06
by ViktorV
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.

Re: DownloadFile, UploadFile and OnDirectoryList

Posted: Sun 22 Dec 2019 22:42
by happylalala
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

Re: DownloadFile, UploadFile and OnDirectoryList

Posted: Mon 23 Dec 2019 13:46
by tcaduto12068
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.

Re: DownloadFile, UploadFile and OnDirectoryList

Posted: Tue 24 Dec 2019 00:13
by happylalala
Thanks for your reply tcaduto12068. I will just force the UNIX path.

Cheers

Re: DownloadFile, UploadFile and OnDirectoryList

Posted: Fri 27 Dec 2019 07:56
by ViktorV
As tcaduto12068 said, Windows does not care if the slashes are / or \, so you can try using the Unix format.