2
votes

I can successfully download a file from my ftp server using:

ftp.get(chosenFile,chosenFile);

Where chosenFile is simply a string with the name of the file.

However these are downloaded to the Debug folder of my Delphi project so...

1.) How can I specify where the files should be downloaded to. 2.) How can I make TOpenDialog automatically open to that location after downloading?

2
[SOLVED] I solved my own problem, can't believe it was so simple: 1.Specify the director where the file should be downloaded to as the second parameter: ftp.get(chosenFile,'C:\Temp\'+chosenFile); 2.Set the initial directory of the TOpenDialog as follows: dlg.InitialDir := 'C:\Temp';Robert Henning
1. Specify a path as well as a filename for the local file. 2. Set the OpenDialog.FileName and OpenDialog.InitialDir.Ken White

2 Answers

3
votes

You can specify a full path in the destination file, to specify the exact location. You can specify that same path as the initial dir of the open dialog.

You could also set the working directory using the SetCurrentDir procedure.

Alternatively, you can use ftp.Get(chosenFile, Stream), where Stream can be an instance of any TStream descendant, like a TFileStream (opened to write to your desired target file), or even a TMemoryStream, if you don't need the file to be on disk at all.

In fact, the Get overload that accepts the destination filename, will just create a TIdFileStream, depending on the exact parameters, and call the other overload.

1
votes

[SOLVED] I solved my own problem, can't believe it was so simple: 1.Specify the director where the file should be downloaded to as the second parameter: ftp.get(chosenFile,'C:\Temp\'+chosenFile); 2.Set the initial directory of the TOpenDialog as follows: dlg.InitialDir := 'C:\Temp';