+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Nov 2007
    Posts
    4

    Post Help-Me Error In My Source (Files Upload)

    //CLIENTE//
    procedure TFCliente.BtnUpClick(Sender: TObject);
    var
    //
    FStream:TFileStream;
    Nome:String;
    Tamanho:Integer;
    //
    begin
    //---------------------------------//
    If Open.execute then
    Begin
    Nome:= ExtractFileName(Open.FileName);
    FStream:=TFileStream.Create(Open.Filename,FMOpenRe ad);
    try
    begin
    FStream.Position:=0;
    Tamanho:= FStream.Size;
    CS.Socket.SendText('UP'+'|'+Nome+'|'+(IntToStr(Tam anho)));
    CS.Socket.SendStream(FStream);
    Status.Lines.Add('Nome: '+Nome+' | Tamanho: '+IntToStr(Tamanho)+' | Enviado com sucesso.')
    End;
    except
    Showmessage('Impossivel Enviar Arquivo');
    FStream.Free;
    end;
    end;
    end;

    //----Servidor----///
    procedure TFServidor.ssClientRead(Sender: TObject;
    Socket: TCustomWinSocket);
    var
    Comando,Tudo,Nome,Tamanho,Pasta:String;
    Buf:Int64;
    Len,RevLen:Integer;
    begin
    Tudo:=Socket.ReceiveText; //Recebe Tudo que o cliente envia;
    //--Comando Enviar--//
    Comando:=Copy(Tudo,0,2);
    //--Lê o Nome do arquivo--//
    Nome:=Copy(Tudo,4,Length(tudo));
    Nome:=Copy(Tudo,4,Pos('|',Nome)-1);
    //--Lê o tamanho do arquivo--//
    Tamanho:=Copy(Tudo,Length(Nome)+5,Length(Tudo));
    //


    //Verifica os Comandos Enviados pelo servidor//
    If Comando = 'UP' Then
    //
    Edit1.Text:= Comando;
    Edit2.Text:= Nome;
    Edit3.Text:= Tamanho;

    Pasta:= ExtractFilePath(Pasta)+Pasta;
    //-----------------------//
    Len:=SS.Socket.ReceiveLength;
    Buf:=SS.Socket.ReceiveBuf(Buf,Len);
    //-----------------------//
    FStream:=TFileStream.Create(Nome,FmCREATE or FmOPENWRITE and Fmsharedenywrite);
    while Len > 0 do
    begin
    RevLen := Socket.ReceiveBuf(Buf, Sizeof(Buf));
    if RevLen <= 0 then
    Break
    else
    FStream.Write(Buf, RevLen);
    if FStream.Size >= StrToInt(Edit3.Text) then
    begin
    FStream.Free;
    if Messagedlg('Deseja Abrir o arquivo?', mtConfirmation, [MbYes,MbNo],0) = MrYes then
    begin
    ShellExecute(Handle, 'Abrir', pchar(Pasta),nil, nil, SW_NORMAL);
    end;
    Break;
    end;
    end;
    End;


    //-------------------------------------------------------------------------//
    Please, Help-Me.
    Source error?

    Sorry, My English.. Very Very Bad.

  2. #2
    Senior Member Trilithium's Avatar
    Join Date
    Jun 2006
    Location
    Planet Earth
    Posts
    373
    not ur english but the code toooo

    firstoff

    1 u are sending a command i assume (UP + some shitty text)
    2 then u send a stream without any command in it/header????
    .. but on the server side u still try to extract a command from the arriving data???

    3 be aware that the tsocket shit is nonblocking and uses Windows messages this might result in fragmentet data/ not eversything arfrives

    i would recommend rewriteing the whole thing and advise thinking beforehand

    a good old loop and a working protocol should sort things out


  3. #3
    Junior Member
    Join Date
    Nov 2007
    Posts
    4

    Cool Tanks

    Tanks by Help.

    I am from Brazil. :cool:



    Do you have any example of Upload And Download :confused:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Upload file using HTTP Post
    By msrox in forum Delphi Help
    Replies: 1
    Last Post: 08-02-2009, 11:17
  2. delphi 5 Source Code error
    By pakiboy80 in forum General Programming Help
    Replies: 1
    Last Post: 14-09-2007, 11:59
  3. Need free host to upload DLL
    By tjf in forum Off-Topic
    Replies: 4
    Last Post: 21-11-2006, 09:56
  4. Upload file through IE
    By msrox in forum Delphi Help
    Replies: 2
    Last Post: 20-10-2006, 07:58
  5. Sennaspy ftp upload trojan
    By dNs- in forum Malware sources
    Replies: 1
    Last Post: 24-04-2006, 09:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.