Solved

FTP transfer WITH progress bar?

Posted on 2004-08-16
9
542 Views
Last Modified: 2009-07-29
I need to do a built in FTP transfer (both an Upload and a Download) in my vb.net app.. and would like both of them to show a progress bar as the file transfers.

I've got a few ways to do the transfer itself, but I have no idea how to make it update the progress bar WHILE it's updating.

Any help?  The more information as you can give, the better!
0
Comment
Question by:dudinatrix
9 Comments
 
LVL 3

Expert Comment

by:realrael
ID: 11817729
0
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 200 total points
ID: 11818591

Dear dudinatrix,

here you have a better link, since realreal provided one with only VB6. This one is gives you some:

http://www.aspfree.com/c/a/Code%20Examples/Building-a-Basic-FTP-Client-with-VSNet-by-Lance-R

Down the page there is a section:

------
Percent Transferred
 

OK, so now we are transferring files. How do I know the status of the file transfer? First of all, when the transfer is first begun, a StartTransfer event will fire. During the transfer, a Transfer event will fire, and after the transfer is finished, an EndTransfer event will fire. You can use the BytesTransferred property that is available in the Transfer event of the FTP component to keep track of how many bytes have been transferred so far in the current transfer. This information will allow you to create a progress bar. In order to do the math, you will of course need to know the file size. If you are uploading a file to the server, you already know the file size since its local (Use a File system object). If you are downloading a remote file from the server, you’ll need to ask the server how large the file is before initiating the download, by setting the RemoteFile property to the appropriate file and issuing a ListDirectoryLong. Then the DirList event will be fired once for the file you have specified and you can get the filesize parameter of the DirList event.
------

you asked how you could keep track of the update.

I do not know exactly how your code looks like, but try this:

> make sure the ftp works.
> put a progressbar on your form, lets call it progressbar1
> define a variable where the filesize can be stored:  (put this outside any sub)

dim _filesize as long

> put a TIMER on your form, and activate it when the STARTTRANSFER event is fire":

 Private Sub Ftp1_OnDirList(...........) Handles Ftp1.Starttransfer   '<< you might need to change this
  'Timer settings
  Timer1.Enabled
  Timer1.Interval = 200   'a tick every 200 millisec
  Timer1.Start()

  'Progressbar settings
  progressbar1.minimum = 0
  progressbar1.maximum = 100
  progressbar1.step = 1
  progressbar1.value = 0

  'Get the filesize being transferred:   '<< I am not sure how to get the filesize,.. but that should not be the problem for you
   _filesize = ftp1.localfile.filesize '???

 End Sub


> Then we gonna update the progressbvar every time the timer ticks:

   Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     dim progressvalue as integer
     progressvalue = Cint(ftp1.BytesTransferred/_filesize)
     if progressvalue < 0 then
          progressvalue = 0
     elseif progressvalue > 100
          progressvalue = 100
     else
         ' the value is correct and may be passed to the progressbar
     end if  
     progressbar1.value = progressvalue
  End Sub


As you see, you might have to change 2 things to get it properly working, but I hope I gave you the good idea

Try it and maybe you like it!

Daniël
0
 

Author Comment

by:dudinatrix
ID: 11820875
realrael: Thank you, but like Daniël said, I'm looking for a VB.net specific solution rather than VB6.

Daniël:  Thank you VERY much for the detailed post, I really do appreciate it... however, I'm sorry to say that it requires downloading a third party FTP component.. and while it's free, I assume their name will be all over it in my source code and possibly the application itself.  I'd use it if it were for my own use, but I'm writing an application for my company, and would prefer it with no third party references.  Your post did give me a better idea on how to work with the the progress bar during the transfer , so thank you!
0
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
LVL 4

Expert Comment

by:Daniellus83
ID: 11821022

Sorry, but I really didn't do the post to give you any source.. I posted this one detailed on the fact that your have already build your own FTP interface... ("...I've got a few ways to do the transfer itself...")

I though you only needed to add good interface wich handles the progressbar etc...

Am I right?... My posted code doesn't  depend on the 3rd party software/sourcecode...

0
 

Expert Comment

by:Legolas2003
ID: 11821040
Go to this URL: http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=DD5E4A38-7F5B-45E0-9C36-64B987947C20

this is a great component.
If you have problems contact me...
Regards
0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11821106

Okay as I cannot give up:

Here you have a (full) FTP library WITHOUT references!!

>> http://www.codeproject.com/dotnet/dotnetftp.asp?df=100&forumid=3824&exp=0&select=591722


This with the other post should complete the answer?  ;-)
0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 12110314
TheLearnedOne:

realreal didn't post any usefull code since it was only VB6, not really this section I guess...:

(post @ 04:31PM CEST)   "...realrael: Thank you, but like Daniël said, I'm looking for a VB.net specific solution rather than VB6...."
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from 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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now