用delphi6怎么實現上傳文件到指定服務器 用delphi6怎么實現上傳文件到指定服務器.比如圖片等.答案不要是把文件保存到數據庫 。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的服务器采用什么方式来接收文件?socket?ftp?http?... 額,還沒決定好,就是想要一個思路想web一樣在數據庫保存一個路徑,但內容可以隨便保存在什么位置。delphi我不知道是怎么實現的。 用FTP传就可以了。。FtpPutFile(FFtpHandle, Filename, RemoteFile, FTP_TRANSFER_TYPE_BINARY, 255) NMftp這個控件是吧這個控件看了一下說明挺簡單的 用FTP应该是最方便的Indy安装的目录下 有类似的Demo unit UploadFile;interfaceuses Windows, Messages, Variants,SysUtils, Classes,ConstLib, Wininet;Type TOnUpLoadEvent = procedure(Sender:TObject) of object; TUploadFile=class(TComponent) private FInetHandle: HInternet; FFtpHandle: HInternet; FPort: integer; FUserName: string; FHost: string; FPassword: string; procedure SetInetHandle(const Value: HInternet); procedure SetFtpHandle(const Value: HInternet); procedure SetHost(const Value: string); procedure SetPassword(const Value: string); procedure SetPort(const Value: integer); procedure SetUserName(const Value: string); protected public constructor Create(AOwner:TComponent);override; destructor Destroy;override; property InetHandle: HInternet read FInetHandle write SetInetHandle; property FtpHandle: HInternet read FFtpHandle write SetFtpHandle; published function Connect: boolean; function Disconnect: boolean; function DownLoad(RemoteFile: PChar; NewFile: PChar):boolean; function UpLoad(Filename: PChar; RemoteFile: PChar;RemoteDir: PChar): boolean; property Host: string read FHost write SetHost; property UserName: string read FUserName write SetUserName; property Password: string read FPassword write SetPassword; property Port: integer read FPort write SetPort; end;var UploadFile1:TUploadFile;{procedure Register; }implementation{procedure Register;begin RegisterComponents('CaiCom',[TUploadFile]);end; }{ TDownloadFile }function TUploadFile.Connect: boolean;begin try Result := false; // 创建句柄 FInetHandle := InternetOpen(PChar('KOLFTP'), 0, nil, nil, 0); FtpHandle := InternetConnect(FInetHandle, PChar(Host), FPort, PChar(FUserName), PChar(FPassword), INTERNET_SERVICE_FTP, 0, 255); if Assigned(FtpHandle) then begin Result := true; end; except Result := false; end;end;constructor TUploadFile.Create(AOwner: TComponent);begin inherited ;end;destructor TUploadFile.Destroy;begin inherited ;end;function TUploadFile.Disconnect: boolean;begin try InternetCloseHandle(FFtpHandle); InternetCloseHandle(FInetHandle); FtpHandle:=nil; inetHandle:=nil; Result := true; except Result := false; end;end;function TUploadFile.UpLoad(Filename: PChar; RemoteFile: PChar;RemoteDir: PChar): boolean;begin try Result := true; FtpCreateDirectory(FFtpHandle,RemoteDir); FtpSetCurrentDirectory(FFtpHandle,RemoteDir); if not FtpPutFile(FFtpHandle, Filename, RemoteFile, FTP_TRANSFER_TYPE_BINARY, 255) then begin Result := false; end; except Result := false; end;end;function TUploadFile.DownLoad(RemoteFile: PChar; NewFile: PChar): boolean;begin try Result := true; //------------------------ //创建目录 if not DirectoryExists(ExtractFilePath(NewFile)) then if not CreateDir(ExtractFilePath(NewFile)) then begin Result := False; Exit; end; if not FtpGetFile(FFtpHandle, RemoteFile, NewFile, False, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY OR INTERNET_FLAG_RELOAD, 255) then begin Result := false; end; except Result := false; end;end;procedure TUploadFile.SetFtpHandle(const Value: HInternet);begin FFtpHandle := Value;end;procedure TUploadFile.SetHost(const Value: string);begin FHost := Value;end;procedure TUploadFile.SetInetHandle(const Value: HInternet);begin FInetHandle := Value;end;procedure TUploadFile.SetPassword(const Value: string);begin FPassword := Value;end;procedure TUploadFile.SetPort(const Value: integer);begin FPort := Value;end;procedure TUploadFile.SetUserName(const Value: string);begin FUserName := Value;end;end.这个前阵子改网上的例子后的半成品,,没法看下载进度,, http://blog.csdn.net/genispan/archive/2008/11/04/3216923.aspx我的BLOG里面有收藏 可以看看 我用NMFTP是可以上傳東西了,但感覺怪怪的。NMFTP的單元文件我怎么打開不了想了解下它的工作原理 如何动态生成chart? 真正的pascal版zlib库出现了 如何获得tspeedbutton按钮的句柄; 在表單Form還沒顯示出來時取消? 急需ADO中控件的區別 vcl&clx 简单的动态多维数组问题 如何能够重载函数与过程 如何做到按照要求随机从SQL数据库中读出记录啊,谢谢. AI系列仪表通信,在线等待,小弟急用,谢谢啦 怎么样将bmp黑白图,转换成点阵数组形式??? 如何查看已开发程序中组件的版本
FtpPutFile(FFtpHandle,
Filename,
RemoteFile,
FTP_TRANSFER_TYPE_BINARY, 255)
這個控件看了一下說明挺簡單的
Indy安装的目录下 有类似的Demo
uses
Windows, Messages, Variants,SysUtils, Classes,ConstLib,
Wininet;Type
TOnUpLoadEvent = procedure(Sender:TObject) of object;
TUploadFile=class(TComponent)
private
FInetHandle: HInternet;
FFtpHandle: HInternet;
FPort: integer;
FUserName: string;
FHost: string;
FPassword: string;
procedure SetInetHandle(const Value: HInternet);
procedure SetFtpHandle(const Value: HInternet);
procedure SetHost(const Value: string);
procedure SetPassword(const Value: string);
procedure SetPort(const Value: integer);
procedure SetUserName(const Value: string);
protected public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
property InetHandle: HInternet read FInetHandle write SetInetHandle;
property FtpHandle: HInternet read FFtpHandle write SetFtpHandle;
published
function Connect: boolean;
function Disconnect: boolean;
function DownLoad(RemoteFile: PChar; NewFile: PChar):boolean;
function UpLoad(Filename: PChar; RemoteFile: PChar;RemoteDir: PChar): boolean;
property Host: string read FHost write SetHost;
property UserName: string read FUserName write SetUserName;
property Password: string read FPassword write SetPassword;
property Port: integer read FPort write SetPort;
end;
var UploadFile1:TUploadFile;
{procedure Register; }implementation
{
procedure Register;
begin
RegisterComponents('CaiCom',[TUploadFile]);
end; }
{ TDownloadFile }function TUploadFile.Connect: boolean;
begin
try
Result := false;
// 创建句柄
FInetHandle := InternetOpen(PChar('KOLFTP'), 0, nil, nil, 0);
FtpHandle := InternetConnect(FInetHandle,
PChar(Host),
FPort,
PChar(FUserName),
PChar(FPassword),
INTERNET_SERVICE_FTP,
0,
255);
if Assigned(FtpHandle) then
begin
Result := true;
end; except
Result := false;
end;
end;constructor TUploadFile.Create(AOwner: TComponent);
begin
inherited ;end;destructor TUploadFile.Destroy;
begin inherited ;
end;function TUploadFile.Disconnect: boolean;
begin
try
InternetCloseHandle(FFtpHandle);
InternetCloseHandle(FInetHandle);
FtpHandle:=nil;
inetHandle:=nil;
Result := true;
except
Result := false;
end;
end;function TUploadFile.UpLoad(Filename: PChar; RemoteFile: PChar;RemoteDir: PChar): boolean;
begin
try
Result := true; FtpCreateDirectory(FFtpHandle,RemoteDir);
FtpSetCurrentDirectory(FFtpHandle,RemoteDir);
if not FtpPutFile(FFtpHandle,
Filename,
RemoteFile,
FTP_TRANSFER_TYPE_BINARY, 255) then
begin
Result := false;
end;
except
Result := false;
end;
end;function TUploadFile.DownLoad(RemoteFile: PChar; NewFile: PChar): boolean;
begin
try
Result := true;
//------------------------
//创建目录
if not DirectoryExists(ExtractFilePath(NewFile)) then
if not CreateDir(ExtractFilePath(NewFile)) then
begin
Result := False;
Exit;
end;
if not FtpGetFile(FFtpHandle,
RemoteFile,
NewFile,
False, FILE_ATTRIBUTE_NORMAL,
FTP_TRANSFER_TYPE_BINARY OR INTERNET_FLAG_RELOAD,
255) then
begin
Result := false;
end;
except
Result := false;
end;
end;procedure TUploadFile.SetFtpHandle(const Value: HInternet);
begin
FFtpHandle := Value;
end;procedure TUploadFile.SetHost(const Value: string);
begin
FHost := Value;
end;procedure TUploadFile.SetInetHandle(const Value: HInternet);
begin
FInetHandle := Value;
end;procedure TUploadFile.SetPassword(const Value: string);
begin
FPassword := Value;
end;procedure TUploadFile.SetPort(const Value: integer);
begin
FPort := Value;
end;procedure TUploadFile.SetUserName(const Value: string);
begin
FUserName := Value;
end;end.这个前阵子改网上的例子后的半成品,,没法看下载进度,,
我的BLOG里面有收藏 可以看看
,但感覺怪怪的。NMFTP的單元文件我怎么打開不了
想了解下它的工作原理