Get File From the Net |
 |
Create a Delphi application that downloads files from the Internet; add an auto-update feature to your programs. <!-- BEGIN FREQUENCY TEMPLATE -->
<!--more of this feature. Use to link to multi-page features on your own site.--><!--end more of this feature-->
 |
<!--join the discussion. Use to link to relevant forum thread on your site.-->
Join the Discussion |
"Post your views, or look for guidance on the questions and issues that matter to creating a simple ftp download manager in Delphi" Discuss!
|
|
 |
<!--end join the discussion-->
 |
<!--related resources. Use to link to related content on YOUR site.-->
|
 |
<!--end related resources-->
 |
<!--from other guides. Use to link to related "Web Ring" or coordinated content on OTHER Guide sites.--><!--end from other guides-->
 |
<!--elsewhere on the web. Use to link to external sites on the Web.-->
|
 |
<!--end elsewhere on the web--><!--rate this article.-->
 |
 |
<!-- Begin Poll Code -->
About Poll |
This [013001] article is:
|
Awesome |
|
Great |
|
Ok |
|
Not bad |
|
Poor |
|
Current Results |
<!-- End Poll Code --> |
|
<!--end rate this article-->
|
|
<!--END FREQUENCY TEMPLATE--><!-- BEGIN ARTICLE CONTENT -->
If your program relies on Packages or DLLs than deploying new versions of your libraries certainly takes some time. The Internet now provides a fairly easy way to accomplish this task. Adding an auto-update option to your applications could be the best way to keep your Delphi applications up to date.
Let's see how to create the most important piece of code in any FTP application.
Delphi gives us full access to the WinInet API (wininet.pas) which we can use to connect to and retrieve files from any Web site that uses either Hypertext Transfer Protocol (HTTP) or File Transfer Protocol (FTP). For example, we could use the functions inside the WinInet API to: add an FTP browser to any application, create an application that automatically downloads files from a public FTP site or search the Internet site for references to graphics and download only the graphics.
GetInetFile function
uses Wininet;
function GetInetFile
(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName),
INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),
nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer,
SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
|
Note: In order to provide some visual feedback to the user you could add a line like FlashWindow(Application.Handle,True) in the body of the repeat/until block. The FlashWindow API call flashes the caption of your applications name in the task bar.
Usage To call the GetInetFile function you could use the next peace of code:
var FileOnNet, LocalFileName: string
begin
FileOnNet:=
'http://delphi.about.com/library/forminbpl.zip';
LocalFileName:='File Downloaded From the Net.zip'
if GetInetFile(FileOnNet,LocalFileName)=True then
ShowMessage('Download successful')
else
ShowMessage('Error in file download')
end;
|
This code will get the 'forminbpl.zip' file from this site, download it, and save it as 'File Downloaded From the Net.zip'.
Note: Depending on which version of Delphi you have, several components can be found on the Internet page of the VCL palette that are designed to ease the task of Internet enabling your applications. For an example of a FTP component look for TNMFTP in the FastNet VCL page. <!-- END ARTICLE CONTENT -->
<!-- START ARTICLE NEW BOTTOM -->
<!-- START ARTICLE NEW BOTTOM --> |
相关推荐
// Get File objects from Strings File to_file = new File(to_name); // First make sure the source file exists, is a file, and is readable. if (!from_file.exists()) abort("no such source file: " ...
2. 使用Java的`File`类创建并写入这个VBScript文件。 3. 运行VBScript文件,通过`Runtime.getRuntime().exec()`方法调用`cscript`命令执行VBScript,并捕获其输出。 4. 读取并处理VBScript的输出,这将是主板序列号...
"Softimage ICE Node to get the Spectrum from a Wave file" 这个标题意味着我们有一个ICE节点,它的功能是读取.WAV格式的音频文件,并从中计算出频谱信息。WAV是一种无损音频文件格式,广泛用于存储各种音频数据,...
How to get safe and quick access to any file systems? DiskInternals Linux Reader is an easy and short way to solve the problem! While saving, it ignores file security policies. It means that it is ...
System.out.println("Successfully downloaded file from " + remoteUrl + " to " + localFilePath); } catch (IOException e) { System.err.println("An error occurred while downloading the file: " + e....
本文档将详细讲解如何使用C#来压缩多个文件到一个ZIP文件中,特别强调的是只压缩指定文件夹中的文件而不包括子文件夹中的文件。 #### 二、核心代码解析 首先,我们来看一下关键的代码片段: ```csharp using ...
At 'Unit file name': Browse and Select EasyFileSearchReg.pas from the directory where you installed it. At 'Package file name': TEasyFileSearch ( In the directory Projects\Lib ) At 'Description': ...
Oracle P/L SQL实现FTP上传、下载功能,以下是此过程包的头部,包体经常打包处理plb,感兴趣用户可以下载下来。 --Oracle上的FTP功能 Create or Replace Package UTL_FTP AUTHID CURRENT_USER as Type Connection ...
derp = get_from_file ( f ) # returns Match object (list of signatures) that match the file at this file path herp = get_from_path ( f_name ) # this can be a string or a bytestring, will raise...
Query the data from table (database)with the tremendous volume or from the file system, the efficiency may be very slow. While using QuickMemoryFile, regard data table or file system as the data ...
* Additional code and/or components are generally required to get data from other sources than the local file system. These components support most of the HTML 3.2 specifications with many additional...
在这个例子中,我们使用了cURL库代替`file_get_contents()`,并编码了文件内容为base64,以适应API的要求。 在实际开发中,你还需要考虑错误处理、文件大小限制、文件类型验证、API认证(如OAuth)等问题。确保在上...
add a file upload function, there is another find from the delphibbs file upload component, I also be placed in compression bag, and the other is mainly structural adjustment programs, hoping to ...
Query the data from table (database)with the tremendous volume or from the file system, the efficiency may be very slow. While using QuickMemoryFile, regard data table or file system as the data ...
用法 touch [-acm] [-r ref_file] 文件... touch [-acm] [MMDDhhmm[yy]] 文件... touch [-acm] [-t [[CC]YY]MMDDhhmm[.SS]] file... mkdir 创建目录(必须有创建目录的权限) 用法 mkdir [-m 模式] [-p] dirname ....
1. 增加使用代理池功能 2. 增加输出到文件功能 3. 去掉了一些使用syetem函数的... -f FILE, --file FILE read the url from the file -p PROXY, --proxy PROXY use HTTP/HTTPS proxy --shell try to get shell
`FromFile.java`类可能是用于封装文件信息的类,如文件名、文件内容、参数名和内容类型。例如: ```java package com.cn; import java.io.File; import java.io.FileInputStream; import java.io....
you can enter a command into your .htaccess file to stop the directory list from being shown: 为避免这种情况(而不必创建一堆的新index文件),你可以在你的.htaccess文档中键入以下命令,用以阻止目录...
Please include the following file with any support request"是npm(Node.js包管理器)在遇到问题时给出的通用错误提示,要求在寻求支持时附带上npm-debug.log日志文件,这个文件通常包含了详细的错误信息,帮助...
Malformed entry 60 in list file /etc/apt/sources.list (Component) 解决方案 注意到报错提示/etc/apt/sources.list 这个文件第60行格式错误,那么尝试把这行注释掉。先打开这个文件: $ sudoedit /etc/apt/...