Posted on November 6, 2020 at 3:37 pm
Given an FTP URL, you can parse it using TidURI:
uses ... IdFTP, IdFTPCommon, IdURI ... procedure TForm1.btnDownloadFileClick(Sender: TObject); var URL: string; Uri: TIdURI; begin URL := Trim(edURL.Text); Uri := TIdURI.Create(URL); try IdFTP1.Host := Uri.Host; if Uri.Port <> '' then IdFTP1.Port := StrToInt(Uri.Port) else IdFTP1.Port := 21; IdFTP1.ConnectTimeout := 5000; IdFTP1.Username := 'anonymous'; if Uri.Username <> '' then begin IdFTP1.Username := Uri.Username; IdFTP1.Password := Uri.Password; end; IdFTP1.TransferType := IdFTPCommon.TIdFTPTransferType.ftBinary; IdFTP1.Passive := True; try IdFTP1.Connect; try IdFTP1.Get(Uri.Path + Uri.Document, ExtractFilePath(ParamStr(0)) + Uri.Document, True, False); finally IdFTP1.Disconnect; end; ShowMessage('Downloaded!'); except ShowMessage('Error while downloading!'); end; finally Uri.Free; end; end; |
Works with both username:password and anonymous FTP logins:
ftp://demo:password@test.rebex.net/pub/example/pop3-browser.png ftp://speedtest.tele2.net/1MB.zip |
More details on TIdURI here:
http://www.e-iter.net/knowledge/indy9/007878.html
Other Posts
- Set OpenVPN to Listed on a Specific IP Address
- Bash Trim Leading and Trailing Whitespace from a String
- Bash Get Name of Ethernet Network Interface
- VPN Providers with Dedicated Static IP Address
- OpenVPN Iptables Rules
- WireGuard VPN Iptables Rules
- How to Install WireGuard VPN in Debian 10 Buster
- Bash: No space left on device (inodes issue)
Updated Posts
- Add Desktop shortcut for all Windows PC users
- How to pass custom command-lien parameters in InnoSetup
- Programmatically create desktop icon with InnoSetup
- GeneratePress - a Lightweight WordPress Theme 2021
- InnoSetup disable DesktopIcon via command-line
- Use cURL to authenticate with JWT Bearer tokens
- Detect VMWare Virtual Machine
- Detect Microsoft Virtual PC Virtual Machine