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
Solved

Indy Problem

Posted on 2003-11-14
5
465 Views
Last Modified: 2010-04-05
function FileDownload(AConnection: TConnectionInfo;
    ASourceFile: String; var AMemoryStream: TMemoryStream): Integer; overload;
begin
  Result := 0;
  with TidFTP.Create(nil) do
    try
      Host := AConnection.Host;
      Username := AConnection.Username;
      Password := AConnection.Password;
      //Added By Donskie
      TransferType := ftBinary;
      AsciiFilter := False;
      try
        Connect(False);
        Login;
        Get(ASourceFile, AMemoryStream, False);
        AMemoryStream.Position := 0;
      except
        on E: Exception do Result := -1;
      end;
    finally
      Free;
    end;
end;

procedure TfDictation.Button1Click(Sender: TObject);
var
  ftpConnection : TConnectionInfo;
  sPath : String;
  memStream : TMemoryStream;
begin
  with ftpConnection do
  begin
    Host := '202.162.2.58';
    Username := 'user'
    Password := 'temp';
  end;

  memStream := TMemoryStream.Create;

    if FileDownload(ftpConnection, 'Temp/1.mp3' , MemStream) > -1 then
    ShowMessage('Successfull')
  else
    ShowMessage('Error');
   
    MemStream.SaveToFile('e:\temp.mp3');

end;

the 1.mp3 is 500KB file and i can hear anything in it when i tried to download it using anyFTP client. when i tried indy to get it from the server i can't anymore hear anything. the size is the same with the original but has no voice in it.

is there any problem with the indy included in Delphi 7?
0
Comment
Question by:dopors
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 9746136
The IndyFTP server uses TStream in the Store and Retrieve Events. Using TMemoryStream with files can have major problems
when sending data between client / server (or that's my experience at least). I recommend that you use TFileStream instead.

Regards,
  Tomas Helgi
0
 

Author Comment

by:dopors
ID: 9752157
function FileDownload(AConnection: TConnectionInfo;
    ASourceFile: String; var AFileStream: TFileStream): Integer; overload;
begin
  Result := 0;
  with TidFTP.Create(nil) do
    try
      Host := AConnection.Host;
      Username := AConnection.Username;
      Password := AConnection.Password;
      //Added By Donskie
      TransferType := ftBinary;
      AsciiFilter := False;
      try
        Connect(False);
        Login;
        Get(ASourceFile, AFileStream, False);
        AFileStream.Position := 0;
      except
        on E: Exception do Result := -1;
      end;
    finally
      Free;
    end;
end;

procedure TfDictation.Button1Click(Sender: TObject);
var
  ftpConnection : TConnectionInfo;
  sPath : String;
  fileStream : TFileStream;
begin
 with ftpConnection do
  begin
    Host := '202.162.2.58';
    Username := 'user'
    Password := 'temp';
  end;

  fileStream := TFileStream.Create('e:\temp.mp3',fmCreate);

  //'song.mp3'
  if FileDownload(ftpConnection, 'Temp/1.mp3' , fileStream) > -1 then
    ShowMessage('Successfull')
  else
    ShowMessage('Error');
end;

<B>I have tried you suggestion and it is still the same i have attached my code here, maybe i forgot something.</B>
0
 

Author Comment

by:dopors
ID: 9752831
I have already solved this one. can i get back my points on this one.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12791640
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 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