我给你服务端的代码
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, FtpSrv,FtpSrvC, WSocket,WinSock, Menus,shellapi;
ftpserver1.Addr:=LocalIP;
ftpserver1.Port:=inttostr(4331);
ftpserver1.MaxClients:=50;
try
ftpserver1.Start;
show.Caption:='连接成功! ';
except
showmessage('服务器不能启动,请检查! ');
show.Caption:='连接失败!';
end;
SetWindowLong(application.handle,gwl_exstyle,ws_ex_toolwindow);
end;
//检查用户名与密码是否正确 ,不正确结束客户端的连接
procedure TForm1.FtpServer1Authenticate(Sender: TObject;
Client: TFtpCtrlSocket; UserName, Password: TFtpString;
var Authenticated: Boolean);
var
homedir:string;
begin
if (USerName<>'guest') and (password<>'') then
begin
Client.Close;
Exit;
end;
//设置共享的主目录
homedir:=ExtractFilePath(Application.ExeName);
homedir:=homedir+'/update/';
if not DirectoryExists(HomeDir) then
begin
CreateDir(HomeDir);
end;
Client.HomeDir := HomeDir;
end;
//关闭服务器
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
try
FtpServer1.Stop;
show.Caption:='连接断开! ';
except
showmessage('不能断开连接! ');
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
ftpserver1.Start;
show.Caption:='连接成功! ';
except
showmessage('服务器不能启动,请检查! ');
show.Caption:='连接失败! ';
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FtpServer1.Stop;
end;
procedure TForm1.FtpServer1ClientDisconnect(Sender: TObject;
Client: TFtpCtrlSocket; AError: Word);
begin
Client.Close;
end;
/////////////////////////////////////////// 取得本机的ip号
function TForm1.LocalIP : string;
var
phoste
HostEnt;
Buffer:array[0..100] of char;
WSAData:TWSADATA;
begin
result:='';
if WSASTartup($0101, WSAData) <> 0 then exit;
GetHostName(Buffer,Sizeof(Buffer));
phoste:=GetHostByName(buffer);
if phoste = nil then
begin
result:='127.0.0.1';
end
else
result:=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
WSACleanup;
end;
如果你运行这个服务端的代码,看看出现的情况和我的是不是一样,如果程序中有什么问题,还请指出