Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Line of server code to support PUTTING a file from a client to a server via TIdFTPServer

Posted on 2004-11-22
4
Medium Priority
?
182 Views
Last Modified: 2010-04-05
What is the server code needed in the StoreFile procedure to PUT a file from a client to an FTP Server?

Example code for GETTING a file is as follows (from previous postings):

procedure Form1.IdFTPServer1RetrieveFile(ASender: TidFTPServerThread; const AFileName: string; var VStream: TStream);
begin
  VStream := TFileStrea.Create(AFileName, fmOpenRead);
end;

But how do you implement a PUT on the server side?

I'm sure the solution is obvious.
0
Comment
Question by:RoyMakrucki
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 12650578
Something like this: (code courtesy of Bas Gooijen)

function TForm1.TranslatePath(pfad: string): string;  
var  
   i: integer;  
Begin  
   for i:=0 to length(pfad) do  
      if pfad[i]='/' then pfad[i]:='\';  
   for i:=length(pfad)-1 downto 0 do  
   if pfad[i]='\' then  
   begin  
      delete(pfad,i+1,length(pfad)-i);  
      break;  
   end;  
   if copy(pfad,1,1)='\' then delete(pfad,1,1);  
   TranslatePath:=pfad;  
End;

procedure TForm1.IdFTPServer1StoreFile(ASender: TIdFTPServerThread; const AFilename: string; AAppend: Boolean; var VStream: TStream) ;  
begin  
  if FileExists(translatepath(AFilename, ASender.HomeDir)) and AAppend then  
  begin  
    VStream := TFileStream.create( translatepath( AFilename, ASender.HomeDir ) , fmOpenWrite or fmShareExclusive ) ;  
    VStream.Seek( 0, soFromEnd ) ;  
  end  
  else  
    VStream := TFileStream.create( translatepath( AFilename, ASender.HomeDir ) , fmCreate or fmShareExclusive ) ;  
end;  



DragonSlayer.
0
 

Author Comment

by:RoyMakrucki
ID: 12650779
This will create a file on the server, but then I must read from the client data stream and write this to the new file on the server.  How do I do that?  

Thanks for your help
0
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 200 total points
ID: 12651055
Well, interestingly, that's all that you need to do... you created the TFileStream, remember? As data is read, the component will now automatically use the FileStream you created, and save to it... cool huh ;-)
0
 

Author Comment

by:RoyMakrucki
ID: 12659059
Yes, I understand, and it works as you said.  Thanks for your help
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

571 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