Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now