C# Cant to download JDK15 - c#

I'm trying to download JDK15 but i downloading 5307 bytes but this are not the JDK15
using (WebClient wc = new WebClient())
{
wc.DownloadFileAsync(new System.Uri(
"https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe"),
Path.Combine(directoryPackagesPath, "jdk.exe")
);
}

You downloaded a web page instructing you how to access the download:

You cannot directly download that file. If you open it in another browser, or a incognito/private window, you will see this message:
Sorry!
In order to download products from Oracle Technology Network you must
agree to the OTN license terms.
If you open the downloaded file, most likely it's an HTML with this message.

It is illegal, but if you want learn how to do it for some CTF etc.:
Get query what is send after accepting licence by dev tools in your browser.
Send the exact same query by HttpClient and get cookies from response.
Use this cookies to get the file.
If you want this particular version, you can attach it (if licence allows you to do that) to your program by using installer, by resources or even as normal file in output directory.

Related

How to disable Download Prompt like 'do you want to open or save or save_as?'

I'm trying to download a file located on internet site and I know how to do with WebClient class.
But at this case which the site is re-directed to some web address and therefore, I'm considering to use Process.Start("URL address before re-directed") to avoid bit complexity to download through re-directed web address. I even succeeded to download the file through re-directed web address.
However, I'm curious and want to speed up my application by removing some intermediate steps if possible.
If I approach through Process.Start("URL address before re-directed"), the Download Prompt is shown to ask users like 'Do you want to Open? Save? Save_as?'.
And I don't want this Download Prompt is shown and want to save automatically to utilize the file in my application.(If possible, I want to indicate the location(path) to be saved.)
Thank you so much !
Process.Start("Some URL") is just telling the OS to handle the URL. The OS sees an URL and gives it to the default browser. The default browser does whatever it is configured to do. So with Process.Start("Some URL") you can not force the default browser to not show the download prompt.
You are probably looking for HttpWebRequest.AllowAutoRedirect.
Example from MSDN:
HttpWebRequest myHttpWebRequest= (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
And of course you want a file:
using (var stream = myHttpWebResponse.GetResponseStream()) {
using (var fileStream = new FileStream(filePath, FileMode.Create)) {
stream.CopyTo(fileStream);
}
}

How to allow user to download file from asp.net?

I am having problem in asp.net. Actually I am letting my website's visitor to install an window application from that web site. I have added my application without creating installer so it is just an .exe file which is showing a normal form. But the problem is when user tries to download that file an error message is being shown that says that "This file can harm your computer. Do you want to keep this file anyway?" So I don't want to display that message. can you please help me out. Thanks in advance.
This is neither a "problem" of ASP.NET nor the WinForms application. This is a thing that modern browsers do when you download an application or document that might contain (potentially malicious) executable parts. If there was a "this thing won't harm anybody"-flag for downloads, do you think that this would only be set by "nice" developers?
You can try ActiveX to download file from internet explorer browser. This might help. The way to make download in given below.
Example:
public class Downloader
{
public void DownloadFile()
{
using(WebClient webClient = new WebClient())
{
webClient.DownloadFile("http://www.stackoverflow.com/stacks.txt", #"c:\stacks.txt");
}
}
}

How can you run a PHP file without opening a web browser from a C# program?

I am writing a tool which will allow users to communicate with each other over the internet using a server and PHP files that I have set up. I have written it, but right now when I open the PHP files and pass arguments through the URL to create new files on my server, it opens the PHP file in my default browser. This is the code I am using right now to open the PHP files on my server:
private void ExecuteProcess(string FilePath)
{
Process Process = new Process();
Process.StartInfo.FileName = #FilePath;
Process.Start();
}
I want to be able to open files in a similar way without physically opening them in my browser. I have been googling around for a few hours, but whenever I try to user the methods that I find on the internet I get a 406 exception from Visual Studio, saying that the server cannot fufill my request? My write permissions are set to read for these files, do I need to change these?
Thanks for helping a PHP noobie,
-I
I think you want to make an HTTP request to your server. Check the WebRequest class.
When i used the web request class, there was a page 406 error, which meant that the servers acceptable headers were not comparable with the type of data I was requesting. By default, mod security is turned on on apache servers, and I just need to disable it to allow me to download data with the web request class.unfortunately, the server is hosted by a third party, so I will have to contact the web master in order to turn this off. I have opted just to host my own server, and avoid this hassle.

Downloading a file in C# incorrectly returns files that is zero bytes long

So I'm trying to Download a file using WebClient class but the problem is that when the download is finished the file that should be downloaded is 0 byte, I tried uploading the same file without extension and than changing it after download but that didn't help. What Can I do? This is the code I Use
WebClient updateDownloader = new WebClient();
updateDownloader.DownloadFile(new Uri("http://zazaia.ucoz.com/SomeExeFile.exe"),
Application.StartupPath + "\\SomeFile.EXE");
And also have DownloadCompleted event handler which just shows MessageBox and Disposes the WebClient.
There is nothing wrong with the code you have shown and this should work. The problem is on the server which is not returning the file properly. Also make sure that the site you are querying doesn't require some authentication before being able to download files. In addition to that don't forget that a WebClient will not execute any javascript, so if the server relies on it to download the file, this will not happen.
Have you checked that your antivirus is not interfering? Sometimes an automatic scan will lock an executable file being downloaded until it passes. The client code itself looks fine however.
What about the server side? If is one of your own applications serving the download, then it may not be setting the MIME header or even not handling the download correctly at all

How to download big video files using WebClient class

I'm a newbie and I'm developing a windows application. I need to download a video file from my site and that's my issue here. I had designed a custom down-loader, through which I can download images, text files from my site. But I wasn't able download videos from my site. Could anyone please help me out..?
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("http://mysitename.com/Videos/vid.mp4"), "c:\\movie.mp4");
I don't want to download by means of response content dispatch because my client wants me to download through custom browser.. so please let me know solutions from you experts.. thank you
I have tried to download a video file with WebClient and it works. My setup is as below:
I have a virtualdirectory(Video) in defaultwebsite (IIS) which has this video file.
I just use the below code to download the video file to C drive:
var client = new WebClient();
Uri address = new Uri("http://localhost/Video/wildlife.wmv");
client.DownloadFileAsync(address, #"c:\video.wmv");
Also note since you are downloading in Async fashion, wait for about a min for the operation to complete for the full file to be downloaded. Initially it shows 0 bytes but based on the size it takes some time to complete it.
UPDATE: If your server doesnt have the file mime type specified then just add to the collection of mime types that IIS can serve and you can download the file without any problem.
When adding MIME type the following values to be used are (for your scenario):
File Extension: .mp4
MIME Type: video/mp4
To add mime types in IIS follow these links:
For IIS 4,5
For IIS 6
For IIS 7
This sounds more like a server issue, but if you are doubting your code, you may want to try download sync (I have had some issues in the past downloading async). Another way is to use the WebRequest class. If this server is very remote, try pinging beforehand. I think that you should also check to make sure the file is on the server, and if the file is really big, you should check to see if the file finished uploading.

Categories

Resources