Solved

My.Computer.Network.DownloadFile and KeepAlive in VB.NET

Posted on 2009-07-14
2
1,505 Views
Last Modified: 2012-05-07
I have an issue with downloading a file using FTP where I have to use KeepAlive = false otherwise I get an exception:

System.Net.WebException:"The remote server returned an error: (503) Bad sequence of commands"

Is there a way to set KeepAlive = false using the method My.Computer.Network.DownloadFile ?
0
Comment
Question by:jes12345
2 Comments
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 300 total points
ID: 24849303
You'll probably need to use a WebClient object, and set a header....

        Dim wc As New Net.WebClient
        wc.Headers.Set(Net.HttpRequestHeader.Connection, "Keep-Alive")
        wc.DownloadFile("ftp path", "save path")

Wayne
0
 

Accepted Solution

by:
jes12345 earned 0 total points
ID: 24849431
Thanks for the advise-will the code above set Keep-Alive to false?

Also I have found a workaround myself using System.Net.FtpWebRequest. Using this I can set the following:
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(target), FtpWebRequest)
request.KeepAlive = False

However I am not quite sure what I am doing here on the first line - can you advise about this? (DirectCast etc)

Also do you know what are the difference between WebClient, WebRequest and FtpWebRequest?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

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

11 Experts available now in Live!

Get 1:1 Help Now