局域网内两台电脑进行文件传送,如何实现?就想QQ中的那个文件传送!

lwgbest 2003-09-30 09:21:18
各位大虾:
问题如标题,请高手帮忙,急急!
my qq: 7355382
my e_mail: lwgbest@yahoo.com.cn
...全文
283 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
abcwzl 2003-10-24
  • 打赏
  • 举报
回复
good
shmilyjiujiu 2003-10-23
  • 打赏
  • 举报
回复
ding~
hare007 2003-10-20
  • 打赏
  • 举报
回复
mark
myth_2002 2003-10-20
  • 打赏
  • 举报
回复
给你代码,自己找一段就好了
利用socket传输文件
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;

type
TCon = record
FileName : String;
TotalSize : Integer;
Status : Integer;
end;

PCON = ^TCON;

TForm1 = class(TForm)
SS: TServerSocket;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
SS.Port := 9000;
SS.Active := True;
end;

procedure TForm1.SSClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var c : pcon;
begin

c :=new(pcon);
c.FileName := '';
c.TotalSize := 0 ;
c.Status := 0;
Socket.Data := c;
Socket.SendText('已经连接,请输入UPLOAD FILENAME SIZE'#13#10);

end;

procedure TForm1.SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
var C : PCON;
cmd:String;
Buffer : pointer;
nRetr : integer;
fs : TFileStream;
const bufferSize = 1024 ;

begin
C:= Socket.Data ;
case c.Status of
0 :
begin
cmd := trim(Socket.ReceiveText) ;

if Pos('UPLOAD ',uppercase(cmd)) > 0 then
begin
c.FileName := trim(Copy(cmd,Pos(' ',cmd)+1,Length(cmd)));
c.TotalSize := StrToInt(Copy(c.FileName,Pos(' ',c.FileName)+1,Length(c.FileName)));
c.FileName := trim(Copy(c.FileName,1,Pos(' ',c.FileName)));
c.Status := 1;
Socket.Data := C;
Socket.SendText('you can send File !'#13#10);
end;
end;
1 : begin
GetMem(Buffer,BufferSize);
nRetr := Socket.ReceiveBuf(Buffer^,BufferSize);

if not FIleExists('c:\'+c.FileName) then
begin
fs :=TFileStream.Create('c:\'+c.FileName,fmCreate or fmShareDenyNone);
fs.Seek(0,soFromBeginning);
end
else
begin
fs :=TFileStream.Create('c:\'+c.FileName,fmOpenWrite or fmShareDenyNone);
fs.Seek(0,soFromEnd);
end;

fs.WriteBuffer(Buffer^,nRetr);

fs.Destroy;
FreeMem(Buffer);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.Show;
end;

end.




--------------------------------------------------------------------------------
来自:唐晓锋 时间:99-11-30 01:17:19 ID:162654
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;

type
TForm2 = class(TForm)
CS: TClientSocket;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
SendCommand: TButton;
Label1: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure SendCommandClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CSRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.DFM}
function GetFileSize(const FileName: string):integer;
var f : TFileStream;
begin
f := TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
Result :=f.Size;
F.Free;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
with OpenDialog1 do
begin
Execute;
if FileName <> '' then
begin
Edit1.Text := 'UPLOAD '+ ExtractFileName(FileName) +' '+Inttostr(GetFileSize(FileName));
Label1.Caption := FileName;
cs.Socket.SendText(edit1.Text);
end;
end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
CS.Active := True;

end;

procedure TForm2.SendCommandClick(Sender: TObject);
var fs : TFileStream;
Buf : pointer;

begin
//CS.Socket.SendText(Edit1.Text+#13#10);
//Memo1.Lines.Add();
fs := TFileStream.Create(Label1.Caption ,fmOpenRead or fmShareDenyNone);

GetMem(Buf,fs.Size);
fs.Seek(0,soFromBeginning);

fs.ReadBuffer(Buf^,fs.Size);

memo1.Lines.Add('has send : '+inttostr(Cs.Socket.SendBuf(Buf^,fs.Size)));

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
cs.Close;
end;

procedure TForm2.CSRead(Sender: TObject; Socket: TCustomWinSocket);
begin

Memo1.Lines.add(socket.receiveText);

end;

end.
Delphi_Li 2003-10-20
  • 打赏
  • 举报
回复
1、使用Socket通讯,需要定协议。
2、使用Windows的文件操作,需要有对方机器的Windows下的访问权限。
3、使用FTP需要编写Client和Server。

QQ中使用的是方法1。
hawk_js 2003-10-20
  • 打赏
  • 举报
回复
MARK
zousoft 2003-09-30
  • 打赏
  • 举报
回复
很简单的,用Indy的TCP/IP协议就可以,有现成方法!

TIdTCPConnection.WriteFile

Sends an operating system file to the peer on the connection.

function WriteFile(const AFile: String; const AEnableTransferFile: Boolean = False): Cardinal; virtual;

Parameters

const AFile: String

File to send.

const AEnableTransferFile: Boolean = False

Use OS-specific extenstions to send the file. Default value is False.

Return Value

Cardinal - Number of bytes written to the peer.

Description

WriteFile is a Cardinal function used to send the operating system file specified in AFile to the peer on the connection. WriteFile is used to transfer files in server implementations like HTTP and FTP.

When AEnableTransferFile is True, Windows NT and Windows 2000 server can increase the efficiency of tile transfer operations, but cannot support TIdIntercept or progress indicators. AEnableTransferFile has no effect on Windows 95 and Windows 98.

Otherwise, WriteFile calls WriteStream using a TFileStream for the file specified in AFile to perform write operations over the connection.

WriteFile can raise a EIdFileNotFound exception when AFile does not exist on the local file system.
lwgbest 2003-09-30
  • 打赏
  • 举报
回复
怎么了,国庆节了,没人了吗?高手不要走!
1.linux系统介绍 以windows为内核的操作系统有哪些:win10   win8   win7  xp  系统    windows server 以linux为内核的操作系统有哪些:centos  ubuntu  debian   windows和linux  linux:服务器   安全    稳定 高效    windows:办公  家用  2.安装linux注意事项 对centos系统 的基本使用   有哪些文件夹   对文件/文件夹 进行操作  创建 删除  修改 移动 复制   写入 home 存放所有用户文件的根目录  soft :安装软件 cd  ll mkdir 创建文件  touch 空文件  echo sdsd>a.txt       vi a.txt vi c.txt  打开文件  按下i键  改为写入的模式    写完之后保存: 先按下esc 按键再按下:w 保存 :q退出  :wq    写完之后不保存 强制退出  esc  :q! 删除文件/文件夹 rm -rf a.txt  b.txt rm -rf soft 复制 如果复制文件 cp  要复制的文件名   复制出来的文件名子    cp  a.txt   a1.txt 如果复制的是文件夹的 cp -r soft/   soft1 展示一个文件的内容 cat  移动文件  mv  temp1   temp2 重命名 mv  temp1   temp2 查找: find /(查找的路径)  -name   *.txt    b 清屏  clear tab 按键 可以帮助我们把输入的内容补全   3.配置局域网  需要通过ssh软件远程操作linux系统 远程操作centos系统  在windows操作系统通过一款软件来远程操作虚拟电脑的centos系统  ssh软件: xshell  secureCRT 第一步在win10系统下载并且安装ssh软件 secureCRT    第二步:只要知道centos系统所在电脑的公网IP  登录账户和密码      /  win10和centos系统所在的两台电脑在同一个局域网内  局域网IP  登录账户和密码 第三步:centos系统 进行局域网的设置 往网卡写入一些数据   win10写入的方式:桌面的化操作和centos系统写入的方式是不一样的  ip 网关 子网掩码 NM_conteolle。。。 命令  找到往网卡写入数据的文件    重新启动网络服务 开启22端口   重启防火墙服务 网络桥接网络  *************************端口是否开启  4.配置外网  下载软件1.下载并且安装到系统 node.js环境   npm install bootstrap   默认的镜像库 centos系统    yum install  服务名     默认的镜像库  2.自己下载服务  wget 服务的网络地址 自己单独安装  比较灵活 安装难度大 windows系统  exe文件 linux       rpm包

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧