Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2010, 04:50 PM
passpass passpass is offline
Member
 
Join Date: Nov 2002
Posts: 41
Default Uploading and Downloading Files - FTP

Hey all,

What would be the easiest way to let my program download and upload files from and to my ftp server ? I read online about using the Indy components but tried to understand them and it's over my head

Basically, I want to be able to let my application download a predefined file in a predefined directory on demand to a directory I specify in my application directory overwriting any same named file of course.

I remember I once made an application that got files from a ftp server but that was years ago and I don't remember me using the Indy components at all...
Reply With Quote
  #2  
Old 05-16-2010, 06:00 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

Just copy the code and paste it (Very easy).

http://www.swissdelphicenter.ch/en/showcode.php?id=2201
http://www.swissdelphicenter.ch/en/showcode.php?id=1095
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 05-16-2010, 07:33 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default

Quote:
Originally Posted by passpass View Post
Hey all,

What would be the easiest way to let my program download and upload files from and to my ftp server ? I read online about using the Indy components but tried to understand them and it's over my head

Basically, I want to be able to let my application download a predefined file in a predefined directory on demand to a directory I specify in my application directory overwriting any same named file of course.

I remember I once made an application that got files from a ftp server but that was years ago and I don't remember me using the Indy components at all...
drop an INDY ftp component on your form IdFTP - i renamed it to ftp
the sample below shows the code to upload a file named test.txt on your local drive and renamed index.html up on the server

ftp.Host := 'xyz.com';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('test.txt','index.html');
ftp.Quit;
ftp.Disconnect
Reply With Quote
  #4  
Old 06-20-2010, 09:06 AM
jeidee jeidee is offline
Junior Member
 
Join Date: Oct 2009
Posts: 24
Send a message via Yahoo to jeidee
Default

Quote:
Originally Posted by arwar View Post
drop an INDY ftp component on your form IdFTP - i renamed it to ftp
the sample below shows the code to upload a file named test.txt on your local drive and renamed index.html up on the server

ftp.Host := 'xyz.com';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('test.txt','index.html');
ftp.Quit;
ftp.Disconnect
hi can u upload here a sample form with source code pls
Reply With Quote
  #5  
Old 06-20-2010, 03:57 PM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default ftp demo

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdFTP;
type
TForm1 = class(TForm)
ftp: TIdFTP;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin

ftp.Host := 'xyz.com';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('index.html','index.html'); //upload
ftp.Put('baseball.html','xyz.html'); //upload
ftp.Get('xyz.html','baseball2.html'); //download
ftp.Quit;
ftp.Disconnect;

end;
end.
Reply With Quote
  #6  
Old 07-18-2010, 10:18 AM
coppo22 coppo22 is offline
Junior Member
 
Join Date: Apr 2010
Posts: 24
Default

Quote:
Originally Posted by arwar View Post
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdFTP;
type
TForm1 = class(TForm)
ftp: TIdFTP;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin

ftp.Host := 'xyz.com';
ftp.Username := 'username';
ftp.password := 'password';
ftp.Connect;
ftp.Put('index.html','index.html'); //upload
ftp.Put('baseball.html','xyz.html'); //upload
ftp.Get('xyz.html','baseball2.html'); //download
ftp.Quit;
ftp.Disconnect;

end;
end.
hi all . i need the same code but i have to upload the all files inside a local directory not only one . how can i do it ????

thank's
Reply With Quote
  #7  
Old 07-19-2010, 04:18 AM
arwar arwar is offline
Member
 
Join Date: May 2010
Posts: 31
Default

if you are saying that you have a batch of files in a local directory that need to be uploaded, then add them to a list and loop through it.
Reply With Quote
  #8  
Old 07-19-2010, 10:00 AM
coppo22 coppo22 is offline
Junior Member
 
Join Date: Apr 2010
Posts: 24
Default

here there is a solution for UPLOAD ALL FILE OF ONE DIRECTORY

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdFTP;

type
  TForm1 = class(TForm)
    IdFTP1: TIdFTP;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;


    procedure FormCreate(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


    procedure TForm1.FormCreate(Sender: TObject);
var
  F: TextFile;
  S: string;
  fl : TStringList;
  i:integer;

  procedure ListFileDir(Path: string; FileList: TStrings);
  var
    SR: TSearchRec;

  begin
    if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
      begin
        repeat
          if (SR.Attr <> faDirectory) then
            begin
               FileList.Add(SR.Name);
            end;
        until FindNext(SR) <> 0;
        FindClose(SR);
      end;
  end;
begin
  fl := TStringList.Create;
  ListFileDir('c:\pippo\*.*',fl);

  if FileExists('setting.ini') then 
    begin
      AssignFile(F, 'setting.ini');
      Reset(F);
      ReadLn(F, S);
      Edit1.Text := S;
      ReadLn(F, S);
      Edit2.Text := S;
      ReadLn(F, S);
      Edit3.Text := S;
      ReadLn(F, S);
      Edit4.Text := S;
      ReadLn(F, S);
      Edit5.Text := S;
      CloseFile(F);
    end
  else
    ShowMessage('file SETTING.INI non trovato o non configurato');


  idftp1.Host:=edit1.Text;
  idftp1.Username:=edit2.Text;
  idftp1.Password:=edit3.Text;
  idftp1.Connect();
  IdFTP1.ChangeDir('/ftp/');
  for i := 0 to fl.Count -1 do
    begin
      idftp1.Put('c:\pippo\'+fl[i],fl[i]);
    end;
  fl.Free;

end;


end.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:05 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.