Solved

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

Posted on 2009-07-14
2
1,501 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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

10 Experts available now in Live!

Get 1:1 Help Now