转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
TCP/IP (五)         ★★★★

TCP/IP (五)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2125 更新时间:2009/4/23 18:43:56
nbsp; raise EProtocolError.Create(''''FTP'''',f_status_txt,f_status_nr)
        else begin
          self.response;
          f_busy:=false;
          end;
        end;
      end;
    end;
  end;
(*@\\\0000000301*)
(*@/// procedure t_ftp.noop;                                 // NOOP command *)
procedure t_ftp.noop;
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''NOOP'''');
  self.response;
  end;
(*@\\\0000000501*)
(*@/// procedure t_ftp.changedir(const f_dir:string);        // CWD command *)
procedure t_ftp.changedir(const f_dir:string);
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''CWD ''''+f_dir);
  self.response;
  end;
(*@\\\*)
(*@/// procedure t_ftp.removefile(const filename:string);    // DELE command *)
procedure t_ftp.removefile(const filename:string);
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''DELE ''''+filename);
  self.response;
  end;
(*@\\\*)
(*@/// procedure t_ftp.removedir(const dirname:string);      // RMD command *)
procedure t_ftp.removedir(const dirname:string);
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''RMD ''''+dirname);
  self.response;
  end;
(*@\\\*)
(*@/// procedure t_ftp.makedir(const dirname:string);        // MKD command *)
procedure t_ftp.makedir(const dirname:string);
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''MKD ''''+dirname);
  self.response;
  end;
(*@\\\*)
(*@/// procedure t_ftp.renamefile(const prior,after:string); // RNFR and RNTO commands *)
procedure t_ftp.renamefile(const prior,after:string);
begin
  if f_busy then  raise(EProtocolBusy.create);
  if not f_logged_in then login;
  self.SendCommand(''''RNFR ''''+prior);
  self.response;
  self.SendCommand(''''RNTO ''''+after);
  self.response;
  end;
(*@\\\*)

(*@/// function t_ftp.do_write:boolean; *)
function t_ftp.do_write:boolean;
var
  ok:integer;
begin
  result:=false;
  if f_socket=invalid_socket then EXIT;

  ok:=f_stream.read(f_buffer^,buf_size);
  if ok>0 then
    write_buf(f_socket,f_buffer^,ok);
  result:=ok>0;
  end;
(*@\\\0000000501*)
(*@/// function t_ftp.do_read:boolean; *)
function t_ftp.do_read:boolean;
var
  ok,ok2:integer;
  h:integer;
  p: pointer;
begin
  result:=false;
  if f_socket=invalid_socket then EXIT;
  read_var(f_socket,f_buffer^,buf_size,ok);
  p:=f_buffer;
  h:=ok;
  while ok>0 do begin   (* just to be sure everything goes into the stream *)
    ok2:=0;             (* Delphi 2 shut up! *)
    case f_mode_intern of
      tftp_download: ok2:=f_stream.write(p^,ok);
      tftp_getdir:   ok2:=f_dir_stream.write(p^,ok);
      end;
    dec(ok,ok2);
    p:=pointer(longint(p)+ok2);
    end;
  result:=h>0;
  if assigned(f_ondata_got) then
    f_ondata_got(self,f_mode_intern,h);
  end;
(*@\\\0000000901*)

(*@/// procedure t_ftp.finish_upload; *)
procedure t_ftp.finish_upload;
begin
  while do_write do ;
  f_eof:=false;
  shutdown(f_socket,1);
  closesocket(f_socket);
  f_async:=true;
  self.response;
  f_async:=false;
  if assigned(f_onaction) then
    f_onaction(self,f_mode_intern);
  f_busy:=false;
  end;
(*@\\\0000000901*)
(*@/// procedure t_ftp.finish_download; *)
procedure t_ftp.finish_download;
begin
  while do_read do ;
  f_eof:=false;
  shutdown(f_socket,1);
  closesocket(f_socket);
  f_stream.seek(0,0);  (* set the stream back to start *)
  if assigned(f_onaction) then
    f_onaction(self,f_mode_intern);
  f_busy:=false;
  end;
(*@\\\0000000701*)
(*@/// procedure t_ftp.finish_getdir; *)
procedure t_ftp.finish_getdir;
begin
  f_eof:=false;
  while do_read do ;
  f_eof:=false;
  shutdown(f_socket,1);
  closesocket(f_socket);
  self.SendCommand(''''TYPE I'''');  (* always use binary *)
  self.response;
  f_dir_stream.seek(0,0);  (* set the stream back to start *)
  f_cur_dir.clear;
  f_cur_dir.LoadFromStream(f_dir_stream);
  f_dir_stream.clear;
  f_cur_dir_index:=0;
  if assigned(f_onaction) then
    f_onaction(self,f_mode_intern);
  f_busy:=false;
  end;
(*@\\\0000000901*)

(*@/// procedure t_ftp.get_datasocket; *)
procedure t_ftp.get_datasocket;
var
  po: integer;
  ip: longint;
  s,t: string;
  temp_socket: TSocket;
  SockInfo:TSockAddr;
  f_data_socket_number: smallint;
begin
  f_socket:=INVALID_SOCKET;
(*@///   if self.passive then  ask for the port and open the socket active *)
if self.passive then begin
  self.SendCommand(''''PASV'''');
  self.response;
  if f_status_nr<>227 then
    raise EProtocolError.Create(''''FTP'''',f_status_txt,f_status_nr)
  else begin
    s:=copy(f_status_txt,pos(''''('''',f_status_txt)+1,length(f_status_txt));
    s:=copy(s,1,pos('''')'''',s)-1);

    po:=posn('''','''',s,4);
    t:=copy(s,1,po-1);
    while pos('''','''',t)<>0 do
      t[pos('''','''',t)]:=''''.'''';

(*@///     ip_address:=Winsock.Inet_Addr(PChar(t));  { try a xxx.xxx.xxx.xx } *)
(*$ifdef ver80 *)
  t:=t+#0;
  ip_address:=Winsock.Inet_Addr(PChar(@t[1]));  (* try a xxx.xxx.xxx.xx first *)
(*$else *)
 (*$ifopt h- *)
  t:=t+#0;
  ip_address:=Winsock.Inet_Addr(PChar(@t[1]));  (* try a xxx.xxx.xxx.xx first *)
 (*$else *)
  ip_address:=Winsock.Inet_Addr(PChar(t));  (* try a xxx.xxx.xxx.xx first *)
 (*$endif *)
(*$endif *)
(*@\\\0000000801*)
    s:=copy(s,po+1,length(s));
    try
      f_data_socket_number:=strtoint(copy(s,1,pos('''','''',s)-1))*256
                           +strtoint(copy(s,pos('''','''',s)+1,length(s)));
      f_socket:=self.create_socket;
      if f_async_data then
        winsock.WSAAsyncSelect(f_socket,f_handle,uwm_socketevent+1,
          fd_connect or fd_read or fd_write or fd_accept);
      self.connect_socket(f_socket, f_data_socket_number, ip_address);
    except
      f_socket:=INVALID_SOCKET;
      end;
    end;
  end
(*@\\\0000000F01*)
(*@///   else                  send the port and open the socket passive *)
else begin
  ip:=my_ip_address;
  self.SendCommand(''''PORT ''''+inttostr(ip and $000000ff       )+'''',''''+
                            inttostr(ip and $0000ff00 shr 8)+'''',''''+
                            inttostr(ip and $00ff0000 shr 16)+'''',''''+
                            inttostr(ip and $ff000000 shr 24)+'''',''''+
                            inttostr(f_port and $ff00 shr 8   )+'''',''''+
                            inttostr(f_port and $00ff         ));
  self.response;
&n

上一页  [1] [2] [3]  下一页


[Delphi程序]Delphi 程序员代码编写标准指南 (五)  [Delphi程序]TCP/IP (四)
[Delphi程序]TCP/IP (三)  [Delphi程序]TCP/IP 使网络连接驱向简单化(二)
[Delphi程序]TCP/IP 使网络连接驱向简单化  [VB.NET程序]用VB5 Winsock控件创建TCP\IP客户机 服务器程序
[MySql]Linux TCP/IP 协议栈源码分析(一)  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台