Hi there
i use from following code for download a file from ftp server but it doesn't work......
what's that problem ?!...... -
//FTP Class
-
public event DownloadProgressChangedEventHandler DownloadProgressChanged;
-
public event AsyncCompletedEventHandler DownloadFileCompleted;
-
-
public void Download(string fileName,string savePath)
-
{
-
-
WebClient client = new WebClient();
-
client.Credentials = new NetworkCredential(loginUsername, loginPass);
-
-
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
-
-
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
-
-
client.DownloadFileAsync(new Uri(ftpUrl + fileName), savePath);
-
}
-
-
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
-
{
-
if (this.DownloadProgressChanged != null) this.DownloadProgressChanged(sender, e);
-
}
-
-
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
-
{
-
if (this.DownloadFileCompleted != null) this.DownloadFileCompleted(sender, e);
-
}
-
-
-
//Form Class
-
-
FtpManager manager = new FtpManager(ftpUrl, username, password, FtpManager.FtpMethod.TransferFile);
-
-
manager.DownloadProgressChanged += new DownloadProgressChangedEventHandler(manager_DownloadProgressChanged);
-
manager.DownloadFileCompleted += new AsyncCompletedEventHandler(manager_DownloadFileCompleted);
-
manager.Download(item.Text, "c:\\");
-
-
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?
tlhintoq 3,525
Recognized Expert Specialist
You might like to look at these two lines again. - public void Download(string fileName,string savePath)
-
...
-
manager.Download(item.Text, "c:\\");
-
There is also a good possibility that this will cause you trouble - 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
excuse me for my bad english.....
my problem is in its progressChanged event. -
void manager_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
-
{
-
lblUpDownStatus.Text = FormatSize(e.BytesReceived) + " from " +
-
FormatSize(e.TotalBytesToReceive) + " recieved... " +
-
e.ProgressPercentage.ToString() + "%";
-
}
-
e.TotalBytesRec eived is negative in its representation. .....
why?....i don't know...
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.
e.TotalBytesToR eceive is -1 and e.ProgressPerce ntage is 0.....
with override GetWebRequest doesn't work too....... -
class MyWebClient : WebClient
-
{
-
protected override WebRequest GetWebRequest(Uri address)
-
{
-
FtpWebRequest request = (FtpWebRequest)base.GetWebRequest(address);
-
request.UsePassive = false;
-
return request;
-
}
-
}
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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
|
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");
|
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...
|
by: belgie |
last post by:
How can I retrieve an image (.jpg) from a web site using http with VB
dotnet?
thanks
Bill
| |
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)
|
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.
|
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...
|
by: ad |
last post by:
How can I download a file form Server to client?
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |