Solved

File Transfer

Posted on 2002-06-04
4
256 Views
Last Modified: 2010-05-18
how can i send file from peer to peer (from client to server an the vise versa).
i'm looking for code if available.
Fayiz
0
Comment
Question by:fayiz
4 Comments
 
LVL 1

Accepted Solution

by:
bnemmers earned 250 total points
ID: 7054281
This code will send a file out a open socket.

procedure TSendDataThread.SendFile;
var
  SocketStream: TWinSocketStream;
  FileStream: TFileStream;
  StreamInfo: TStreamInfo;
  FileName: string;
begin
  FileName := ExtractFileName(fStreamInfo.StreamStr);
  FileStream := TFileStream.Create(fStreamInfo.StreamStr, fmOpenRead or fmShareDenyWrite);
  SocketStream := TWinSocketStream.Create(frmMain.csMain.Socket, 60000);
  try
    if (not Terminated) and (frmMain.csMain.Active) then
    begin
      try
        StreamInfo.StreamCmd := SENDFILECMD;
        StreamInfo.StreamSize := FileStream.Size;
        StreamInfo.StreamStr := FileName;
        SocketStream.Write(StreamInfo, SizeOf(TStreamInfo));
        SocketStream.CopyFrom(FileStream, FileStream.Size);
      except
        if not(ExceptObject is EAbort) then
          Synchronize(HandleExeption);
      end;
    end;
  finally
    frmMain.csMain.Socket.Close;
    SocketStream.Free;
    FileStream.Free;
  end;
end;

Good luck Bill
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054949
if you prefer blocking sockets using Indy then take a look at :

http://lee.nover.has.his.evilside.org/isapi/pas2html.dll/pas2html?File=/delphi/MiscFiles/vn_common

check out lnVidTypes and lnVidFuncs for SendFile and ReceiveFile
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010455
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from bnemmers

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 120
error 1.1 400 Bad request idhttp delphi 18 55
Delphi application Soap connection 5 96
Create a path if not exists 7 69
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now