Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress bar while uploading a file

Status
Not open for further replies.

dr8570

Programmer
Sep 5, 2010
1
0
0
TR
Hello. I need help for showing the progress while uploading a file to my ftp server. I dropped a TProgressBar on my form and want to show the upload progress in it.
My upload codes are like this.

procedure UploadMyFile(File2Upload:pchar; targetfilename:pchar);

const
TheFtpPort=21;

begin

intopen := internetopen('iexplore',INTERNET_OPEN_TYPE_DIRECT,nil,nil,0);
intconn := internetconnect(intopen,'ftp_path',TheFtpPort,'userid','password',INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
sleep(100);
ftpputfile(intconn,File2Upload,targetfilename,FTP_TRANSFER_TYPE_UNKNOWN,0);
internetclosehandle(intconn);
internetclosehandle(intopen) ;

end;

procedure TForm2.Upload1Click(Sender: TObject);

begin
uploadmyfile('test.doc', 'document/test.doc');

end;

Thx for any advice
 
Looks like you need to look into using other functions.

FtpOpenFile
InternetWriteFile

When you use InternetWriteFile, you will get a number of bytes written. Use that to update your progress bar.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
If you use the Indy TIdFTP component, it allows you to attach to it's OnWork event, so that you can update your progress bar while it is performing a transfer.
 
Yes, to make a long story short, you need some measurement of how much data has been sent (obviously). So a the beginning, you need to know the total size of the file (for the max position of the progress bar) and at any given point the amount which has been transferred for the position.

Of course this is the common sense part, basically. There are a wide range of methods you can use to get this. I work directly with sockets, so I measure as I send individual packets of data. Otherwise, I've never worked with any other pre-built components like TIdFTP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top