Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-14
2
Medium Priority
?
1,607 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 48

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 1200 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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…
Suggested Courses

916 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