连接:function TfrmFileTransferModule.connect:boolean; begin with IdFTP1 do begin Host := __Host; Username := __userName; Password := __passWord; Port := __Port; try if IdFTP1.Connected then IdFTP1.Disconnect; idftp1.ReadTimeout := 60000; IdFTP1.Connect(True,60000); Result := True; except Result := false; end; end; end;
上传文件 procedure TfrmFileTransferModule.mUpClick(Sender: TObject); var __fileName : string; begin if OpenDialog1.Execute then begin //检查文件是否存在 if not FileExists(OpenDialog1.FileName) then exit; try IdFTP1.ChangeDir(IntToStr(ModuleID)); idftp1.TransferType :=ftASCII;// ftBinary; idftp1.Passive := True; // 这里分为主动和被动 idftp1.Noop ; IdFTP1.Put(OpenDialog1.Filename,__fileName); Application.MessageBox(pchar('文件上传成功!'),'提示',MB_OK+MB_ICONINFORMATION); except on E :Exception do Raise Exception.Create(E.Message); end; end; getFilecount; end;
上传用这个procedure TfrmFileTransferModule.mUpClick(Sender: TObject); var __fileName : string; begin if OpenDialog1.Execute then begin //检查文件是否存在 if not FileExists(OpenDialog1.FileName) then exit; // 检查服务器是否已经存在此文件 __fileName := ExtractFileName(OpenDialog1.FileName); try idftp1.TransferType :=ftASCII;// ftBinary; idftp1.Passive := True; // 这里分为主动和被动 idftp1.Noop ; IdFTP1.Put(OpenDialog1.Filename,__fileName); Application.MessageBox(pchar('文件上传成功!'),'提示',MB_OK+MB_ICONINFORMATION); except on E :Exception do Raise Exception.Create(E.Message); end; end; end;
begin
with IdFTP1 do
begin
Host := __Host;
Username := __userName;
Password := __passWord;
Port := __Port;
try
if IdFTP1.Connected then IdFTP1.Disconnect;
idftp1.ReadTimeout := 60000;
IdFTP1.Connect(True,60000);
Result := True;
except
Result := false;
end;
end;
end;
procedure TfrmFileTransferModule.mUpClick(Sender: TObject);
var __fileName : string;
begin
if OpenDialog1.Execute then
begin
//检查文件是否存在
if not FileExists(OpenDialog1.FileName) then exit;
try
IdFTP1.ChangeDir(IntToStr(ModuleID));
idftp1.TransferType :=ftASCII;// ftBinary;
idftp1.Passive := True; // 这里分为主动和被动
idftp1.Noop ; IdFTP1.Put(OpenDialog1.Filename,__fileName);
Application.MessageBox(pchar('文件上传成功!'),'提示',MB_OK+MB_ICONINFORMATION);
except
on E :Exception do
Raise Exception.Create(E.Message);
end;
end;
getFilecount;
end;
var __fileName : string;
begin
if OpenDialog1.Execute then
begin
//检查文件是否存在
if not FileExists(OpenDialog1.FileName) then exit;
// 检查服务器是否已经存在此文件
__fileName := ExtractFileName(OpenDialog1.FileName);
try
idftp1.TransferType :=ftASCII;// ftBinary;
idftp1.Passive := True; // 这里分为主动和被动
idftp1.Noop ; IdFTP1.Put(OpenDialog1.Filename,__fileName);
Application.MessageBox(pchar('文件上传成功!'),'提示',MB_OK+MB_ICONINFORMATION);
except
on E :Exception do
Raise Exception.Create(E.Message);
end;
end;
end;
http 与FTP???
那我要把文件上传到这个目录下当然要连接的啦
如果是我上面的猜测,建议你装一个SERVER-U做服务端,即安全也易用.
我来个简洁的
上传begin
IdFTP1.Host := '主机地址';
IdFTP1.Username := '用户名';
IdFTP1.Password := '密码';
if IdFTP1.Connected then IdFTP1.Disconnect;
IdFTP1.Connect();
try
IdFTP1.Put('data/本地文件名','远程文件名');
except
end;
可以看到ip地址
HOSTNAME是什么意思啊?
那密码是取那里的密码的?