473,796 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Download file from ftp with webclient class

19 New Member
Hi there
i use from following code for download a file from ftp server but it doesn't work......
what's that problem ?!......
Expand|Select|Wrap|Line Numbers
  1. //FTP Class
  2.         public event DownloadProgressChangedEventHandler DownloadProgressChanged;
  3.         public event AsyncCompletedEventHandler DownloadFileCompleted;
  4.  
  5.         public void Download(string fileName,string savePath)
  6.         {
  7.  
  8.             WebClient client = new WebClient();
  9.             client.Credentials = new NetworkCredential(loginUsername, loginPass);
  10.  
  11.             client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
  12.  
  13.             client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
  14.  
  15.             client.DownloadFileAsync(new Uri(ftpUrl + fileName), savePath);
  16.         }
  17.  
  18.         void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  19.         {
  20.             if (this.DownloadProgressChanged != null) this.DownloadProgressChanged(sender, e);
  21.         }
  22.  
  23.         void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  24.         {
  25.             if (this.DownloadFileCompleted != null) this.DownloadFileCompleted(sender, e);
  26.         }
  27.  
  28.  
  29. //Form Class
  30.  
  31. FtpManager manager = new FtpManager(ftpUrl, username, password, FtpManager.FtpMethod.TransferFile);
  32.  
  33. manager.DownloadProgressChanged += new DownloadProgressChangedEventHandler(manager_DownloadProgressChanged);
  34. manager.DownloadFileCompleted += new AsyncCompletedEventHandler(manager_DownloadFileCompleted);
  35. manager.Download(item.Text, "c:\\");
  36.  
  37.  
Jul 25 '09 #1
6 11293
tlhintoq
3,525 Recognized Expert Specialist
Hi there
i use from following code for download a file from ftp server but it don't work......
what's that problem ?!.....
Is this a test for the rest of us?
Perhaps you would like to elaborate on the problems you are having.
"Doesn't work" is a little vague. Do you get errors/exceptions? Download never starts? Download starts but you get no progress events? You get progress but never finishes?
Have you put in breakpoints and walked through the code as it executes, checking all the values are what you expected them to be?
Have you watched the output window for errors as it runs?
Jul 25 '09 #2
tlhintoq
3,525 Recognized Expert Specialist
You might like to look at these two lines again.
Expand|Select|Wrap|Line Numbers
  1.  public void Download(string fileName,string savePath)
  2. ...
  3. manager.Download(item.Text, "c:\\");
  4.  
There is also a good possibility that this will cause you trouble
Expand|Select|Wrap|Line Numbers
  1. client.DownloadFileAsync(new Uri(ftpUrl + fileName), savePath);
since I see no effort to make sure the ftpUrl and filename will merge together in a valid path.
EX:
ftp:\\mywebsite .com
+
FileToDownload. jpg
=
ftp:\\mywebsite .comFileToDownl oad.jpg
Jul 25 '09 #3
sajjadlove
19 New Member
excuse me for my bad english.....
my problem is in its progressChanged event.

Expand|Select|Wrap|Line Numbers
  1.         void manager_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  2.         {
  3.             lblUpDownStatus.Text = FormatSize(e.BytesReceived) + " from " +
  4.                 FormatSize(e.TotalBytesToReceive) + " recieved... " +
  5.                 e.ProgressPercentage.ToString() + "%";
  6.         }
  7.  
e.TotalBytesRec eived is negative in its representation. .....
why?....i don't know...
Jul 25 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
Is the value -1 ?
Does the value keep changing as progress is made?

I don't do much FTP coding, so it's just a guess for me.
If someone knows more, please chime in.
Jul 25 '09 #5
sajjadlove
19 New Member
e.TotalBytesToR eceive is -1 and e.ProgressPerce ntage is 0.....
with override GetWebRequest doesn't work too.......

Expand|Select|Wrap|Line Numbers
  1.     class MyWebClient : WebClient
  2.     {
  3.         protected override WebRequest GetWebRequest(Uri address)
  4.         {
  5.             FtpWebRequest request = (FtpWebRequest)base.GetWebRequest(address);
  6.             request.UsePassive = false;
  7.             return request;
  8.         }
  9.     }
  10.  
Jul 26 '09 #6
tlhintoq
3,525 Recognized Expert Specialist
Throughout .NET -1 is used to represent "no such value" where a positive value is expected.
Look at a combobox. If there is a selection made, the return from "SelectedIn dex" with be the Items[] index which is zero or higher. If a combobox returns -1 for the SelectedIndex it means there is no selection made.

I'm going to bet the reason you get -1 for the BytesToReceive is because there are no bytes to receive. The file you are trying to download couldn't be located.

Now you have to work out *why* it couldn't be located. Bad log in credentials, no permission to download, bad file path, etc. etc.
Jul 26 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4691
by: Ole Hanson | last post by:
Hi It seems to be virtually impossible to perform a download of more than 2 files at the time from any website? The same limitation seems to be put on IE, if I'm using that as Client. I want to create a simple download manager, that can perform mayby 25 downloads at the same time. What presents the limitation? The WebClient class or the server in the other end?
2
3724
by: Max | last post by:
I need help in vb.net to download a binary file off another web site and save to it to the server. Not from the client. Server to server. Can anyone point me to the right classes to use at least? filestream.. one of the web classes... ?? -Max
2
1840
by: John Spiegel | last post by:
Hi all, How does one allow a user to download a file WITH selecting where it should be downloaded to on their machine? Also, when using the WebClient.Download method, will the destination path written in Windows format (backslashes, etc.) translate across client platforms? Is there a better way? WebClient wc = new WebClient(); wc.DownloadFile(Server.MapPath(@"Downloads\MyFile.pdf"), @"C:\Temp\TheirFile.pdf");
0
1444
by: Jeremy | last post by:
Hi all, I'm using the webclient class in VB.net to download a web page and save it locally. I have a few chars in the html that appear fine when the html page is viewed itself in IE, but once the webclient downloads the file, and saves it, if I then try to view the file saved by the webclient, a few chars are completely garbled. Here are a few examples of chars that get wacky...
11
1567
by: belgie | last post by:
How can I retrieve an image (.jpg) from a web site using http with VB dotnet? thanks Bill
18
16408
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6)
19
1890
by: Andrew Chalk | last post by:
How do I do file download from an ASP.NET v1.x page? Specifically if I have a link e.g. "Download" in a datagrid what code will cause the file download dialog to appear to the user? Many thanks.
6
2715
by: Jatin | last post by:
Hey Guys I have a web application that allows users to download files. But the files are not hosted on the webserver. The files are stored on external servers and are referenced by a URL/URI. Since my application restricts the number of downloads for the file per user, i cannot show the user the URL/URI of the server hosting the file. Therefore i need to some how route the file via my webserver, and then use the Response to stream the...
8
6346
by: ad | last post by:
How can I download a file form Server to client?
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.