How to Extract a Zip file automatically after downloaded - c#

In my web application, user can download a zip file, I want to extract that zip file automatically after downloaded.
I want create a batch file and want to execute that after download is complete in client machine, that will extract zip file automatically.
How to achieve in ASP.Net...

It's almost impossible AMAIK. Because let's see what happens behind the scene. When you send a zip file to your client (User Agent, which in this case is browser), you simply send an HTTP response. From that point onward, you have no control over what happens.
Imagine it was possible. I would wrap up a virus in a zip file. Then I would persuade many victims to click a link for their free gift download, and after downloading I would make it unzip, then run and delete all your favorite songs. It's a security concern.
In general, HTTP and JavaScript are not allowed to do much with file system and host OS. Because you don't know what website you might step on while surfing the Internet.

Related

How to serve files stored in FTP space

My ASP.Net MVC application allows you to download files that are stored in a repository accessible via FTP.
I would need to implement the best strategy to serve these files to the client. I could implement a method that downloads the file from FTP and then serves the file through FileResult ... but clearly it does not seem the best way at all (especially in the case of large files the client should first wait for the application to download the file and then wait a second time for the time necessary for the download).
Any indication or help will be appreciated
If the web server can only access the files over FTP, then that's the way to go.
If the files are on a different server, your web server needs to download them from there (either entirely or streaming) before it can serve them to its HTTP clients.
Alternatively both servers could share the same file location, either by attaching the same (virtual) disk or through another network protocol such as NFDlS, SMB, ...

WebClient random behavior

I have very simple code that download files from a web server and here is the code. As i said it is very basic
// use the web client to download
using (var client = new WebClient())
{
// download locally
client.DownloadFile(from, to);
}
But for some client the file does not download completely and does not throw exception. All these client come from different location and all have the same behavior that the WebClient download exactly 10 mb of ANY file above 10mb. A 8mb file is 8mb, a 20mb file is 10mb a 34 mb file is 10mb. The funny thing is we ask those user to stop using the software.
This issue is not related to the computer as we have alot of those user on laptop that the download works fine from home and it doesn't when they are at work and some it's totally reverse, the download doesn't work at work but it does at work. The behavior is also different for client within the same physical office.
We have tried to talk to their IT and they have no problem going on our http browsable directory and downloading many files over 10mb and it works perfectly and they state they never had such issue. The issue seems to spread more and more and since last windows 10 update much more client started to have this issue.
As a side note this download code has been unchanged and running for 5 years with nearly no issues.
Does anyone know why download would complete without any error (in try..catch) without having downloaded the whole file ? and Why would all these different client with the issue would be cut at EXACTLY 10,000 bytes.
Wanted to add that we tried to reinstall .NET Framework for these user in the past without any result thinking it must be an issue with that
I just edited to add this little extra details that the files they are trying to download are on an anonymous access folder so no login required and it is browsable. All user with the issue can use Chrome and Edge to navigate to the folder and right-click and download and the file is complete that way. Only .NET cannot download files above 10mb on their PC.

Write And Read .txt files from FTP with C#

Is it possible to write a txt file on ftp (not upload a file to ftp!) Directly writing a txt file on ftp server) and read from a file on a ftp (not download a file from ftp!) Directly read from a txt file on ftp server? I searched but ı found upload a file and donwload a file with FtpWebRequest class. Note: FTP server uses credentials.
No, it is not possible.
The FTP protocol described in RFC 959 doesn't have any means to achieve what you want.
No, as far as I'm aware, your only option is to download or upload the file. I guess you could short-circuit it a bit by only downloading the file until you got to the part you needed, then aborting. But the whole purpose of FTP is to upload/download FILES, not content.
It's possible with help of third-party virtual file system driver which should be installed in system. There exist third-party applications which let you see the remote FTP location as a virtual disk on your computer. Once the remote FTP location is mounted this way you can use regular file I/O methods to read and write those files. You can create such application as well (not a rocket science with right tools).

saving a text file in client side without asking for permission any time

I need to save a text file on the client side possibly without permission. The case is that I need to save this text file in a shared folder in this or in another machine in the lan. This text file is going to be read automatically by the fiscal printer which will print the fiscal invoice. I have a asp .net web application and the server is not on the same lan with the fiscal printer, so I have to write it on the client-side. Any idea how to do this without asking to the user every time for the security issue.
I need a cross browser solution.
I can accept a solution like, the client is asked only one time a the first printing, but not every time he wants to print a bill. Some kind of asking permission to the client for allowing this website, in order to not repeat the permission asking.
Obviously - this would be a major security breach to download files to the user's computer without them knowing. All browsers have precautions in place to prevent this from happening.
No, you can not do this. Saving a file to a computer without permission in a public folder is not allowed.
You can, however, have your Client install your application which will have the ability to read and write where you want.
A common way that Trojan viruses to this is by giving the Client some goofy program to run that displays a fireworks show or something else quite trivial. While the Client is busy wondering what he's looking at, your virus is installing quietly in the background.
Now, you are probably saying to yourself, "But I am not installing a virus." However, there is no way for a Browser to know if your application is a virus or not. That is why it is not allowed and why you can not do it.
The more applicable scenario for me is:
1- Do your work inside your web application.
2- Get the information that you need to print.
3- Send it to another computer directly (or to a hosted web service) and this computer will act as a host for these files.
4- let your server access this shared folder, and print what you want
You could use a cookie, which won't ask permission. Of course that would only work when cookies are enabled and can store limited amounts of data.

Publish Signed Files?

I built an auto-update feature to my program. It polling an xml in some http url, and in case there is new version is notifies the user and downloading the new files.
I want to allow redistributing of those updates in closed networks without internet connections. The administrators can download all update files and host in some HTTP server in the network.
The problem is that the xml URL will not be the same, so I want to allow change this URL in the program's config file. This is openning the door to malware publishers: they can redistribute my program with other URL in the config file, and then distribute some form of malware through the auto-update system of my program, then the people will say my program is a virus.
I want to block the chance to change the original auto-update xml to block this kind of malware distribution. How do I do that?
I think I understood your problem. But this problem is not yours to handle. The users should only download your application from a trusted source. You cannot stop a user from downloading malware, its their problem if they do so. Also, it is the users that will add/change a URL to the config file and you cannot stop them from adding a malicious URL to the config file. And even if you have the original update URL hard coded in your application, it wouldn't be hard for a user with malicious intent to change it and recompile your application and distribute it. Or else you can use cryptography to ensure that the original URL is unchanged.

Categories