Solved

File Transfer

Posted on 2002-06-04
4
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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