Delphi - upload and download files Indy idFTP control implementation

FTP information preservation and access

When we do FTP related development, in order to facilitate subsequent FTP switching, the general first save FTP account information into a database table, when using Query re-acquired it through.

Typically of the following ways to the FTP information, as follows:

 1   //获取FTP信息
 2   with qTmp do
 3   begin
 4     Close;
 5     SQL.Clear;
 6     SQL.Text := 'SELECT * FROM SYS_FTP_INFO WHERE NAME = ''Test'' ';
 7     Open;
 8     SYS_FTPUSER := FieldByName('USERNAME').AsString;
 9     SYS_FTPPASSWORD := FieldByName('PASSWORD').AsString;
10     SYS_FTPSERVER := FieldByName('IP').AsString;
11     SYS_FTPDIR := FieldByName('PATH').AsString;
12   end;

 

idFTP file download

Get used to download the main function here, three parameters:

Param1: file name (including extension)

Param2: Path (full path to the final location to save the file) you want to save

Param3: Ture / False whether HTTP

General Procedure code is as follows:

. 1    the try 
2      MsgDsp ( ' starts acquiring file, wait! ' );
 . 3      with idFTP do 
. 4      the begin 
. 5        IF Connected the then the Disconnect;
 . 6        the Username: = SYS_FTPUSER;
 . 7        Password: = SYS_FTPPASSWORD;
 . 8        the Host: = SYS_FTPSERVER;
 . 9        Port: = 21 is ;
 10        Connect;
 . 11        ChangeDir (SYS_FTPDIR);
 12 is        the Get (FILENAME, ' C: \ tmp \ ' +FILENAME, True);
 13        IF Connected the then the Disconnect;
 14      End ;
 15      MsgDsp ( ' ! Recipe file for success ' )
 16    the except 
17      ON E: Exception do 
18      the begin 
19        MsgDsp ( ' file retrieval fails, contact IT to handle error messages! : ' + e.Message);
 20 is        the Abort;
 21 is      End ;
 22 is    End ;

 

idFTP file upload

Here the main use Put upload function, two parameters:

Param1: the full path to the file you want to upload

Param2: file name (including extension)

 

General Procedure code is as follows:

. 1    the try 
2      MsgDsp ( ' start uploading files, please wait! ' );
 . 3      with idFTP do 
. 4      the begin 
. 5        IF Connected the then the Disconnect;
 . 6        the Username: = SYS_CLIENTFTPUSER;
 . 7        Password: = SYS_CLIENTFTPPASSWORD;
 . 8        the Host: = SYS_CLIENTTPSERVER;
 . 9        Port: = SYS_PORT;
 10        Connect;
 . 11        ChangeDir (SYS_CLIENTFTPDIR); 
12 is        of Put ( ' C: \ tmp \ ' +FILENAME, ExtractFileName (FILENAME)); 13        IF Connected the then the Disconnect;
 14      End ;
 15      MsgDsp ( ' file uploaded successfully! ' ); 
16
the except 17 ON E: Exception do 18 the begin
19
MsgDsp ( ' file upload fails, please contact the IT confirm ! error message: ' + e.Message); 20 is the Abort; 21 is End ; 22 is End ;

 

Guess you like

Origin www.cnblogs.com/jeremywucnblog/p/11427595.html