Solved

File Transfer

Posted on 2002-06-04
4
260 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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