2

I'm rather new to development and I have a problem which I haven't sound a solution for. I can't seem to find if it is possible or not to solve, anyway..

I want to create an asp page which would allow a user to download a whole folder from an ftp server. The ftp server itself is not on the same physical server as the asp site. To further complicate the issue is that I want to use either explicit or implicit transfer which I can't seem to work in a browser.

The webpage acts as an intermediary between the client and the ftp server, and is meant to be as user friendly as possible. eg. the user just have to press download and it automatically downloads from the ftp server without the use of an installed local client.

  1. client -> asp page -> ftp server
  2. client <- ftp server

My problem is that the asp page does not have the permission to create files on the client system. I have managed to connect to the ftp and try to download all files in a folder but the files do not appear on the client in the target folder.

I might just be searching for the wrong terms but I would appreciate any feedback.

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
Dev edition
  • 133
  • 1
  • 2
  • 8
  • 1
    Let me see if I am understanding you right.. On Server Side,1. you were able to connect to FTP 2. Get all files 3. But when it comes to storing on the client's PC you have difficulty ? The reason I ask is I don't think you can write a file directly into the end-user hard disk.. You can at best create attachment with "Http Response" object and make it available ? – prashantsunkari Mar 24 '13 at 01:08
  • Exactly, I manage to create a connection to the ftp and start a download. You are right with the difficulty on saving it to the end-user hard drive. I only want the webpage to facilitate a connection between the end-user and the ftp. I do not want the webpage to download any files from the ftp and then send them to the end-user. – Dev edition Mar 24 '13 at 01:13
  • Like i said, I'm pretty new to development but I'll definately check the "Http Response" out to se if i can manage to get something to work. – Dev edition Mar 24 '13 at 01:18

3 Answers3

0

when you say "client" I assume you are referring to the asp.net server. In that case you need to check what user the app pool for your website is running under. Then you need to make sure that user has write permissions to the folder you are storing the ftp files in.

The user is most likely network service.

Element
  • 3,981
  • 7
  • 42
  • 51
0

Your ASP site will not be able to write directly to the end user's system. Just think, would you want any website to have direct access to your file system?

You could download the files to a temporary folder on the Web Server, and then use write it in a response to prompt the user to download it.

Here is a SO question regarding downloading files in ASP.NET

Community
  • 1
  • 1
Kevin Anderson
  • 589
  • 4
  • 17
  • Yeah, i figured out that with the permission. The downside of doing it that way is that the transfer time will double since every single transfer has to go through the webserver and then to the end-user. Plus, if you would like to download a folder with 90 files wouldn't you get prompted with 90 "approve download" or something? – Dev edition Mar 24 '13 at 01:26
  • You might be able to download the files to the web server and add them to a zip file to download. You are correct though in that it will take time for the ASP site to download each file and then for the end user's browser to download the .zip file. Here is another SO question regarding downloading ZIP files: http://stackoverflow.com/questions/2670263/asp-net-download-all-files-as-zip – Kevin Anderson Mar 24 '13 at 01:34
  • Thanks for the help, i will definately check it out. Even though I will propably have to revise my initial thought about the function of the site. – Dev edition Mar 24 '13 at 01:38
  • If the end user's PC can reach the FTP site, you could write a single Console app to download the files directly to the end user's file system. I have done this before to download files as a scheduled task. But that requires running an app on the end user's computer instead of a website. Good luck! – Kevin Anderson Mar 24 '13 at 01:41
  • Yeah, i was trying to prevent the need for a local application. However, it seems like it is the easiest way to go. – Dev edition Mar 24 '13 at 04:16
  • I think it just depends on the use case. If this is only for a select few users who need to access the FTP application on the same computer, then I would consider the console app. However, if many different users will need access and they may not be on the same machine every time, maybe doing some testing to determine the amount of time the FTP to ZIP and download required will help you decide the better course of action. At some point, the amount of time it would take for you to install the client on their computers will outweigh the benefits of avoiding the website. – Kevin Anderson Mar 24 '13 at 12:35
0

From our question's comment discussion, looks like you are looking to provide user with a option to download file which you have collected on server side from ftp server

//Connect to your file
FileStream sourceFile = new FileStream(Server.MapPath(@"FileName"), FileMode.Open);
float FileSize= sourceFile.Length;

//Write the file content to a byte Array 
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();

//Build HTTP Response object
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", getContent.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.BinaryWrite(getContent);
Response.Flush();
Response.End();

Please see if the above code helps. Also, check out HTTP Response file Attachment Discussion

Community
  • 1
  • 1
prashantsunkari
  • 959
  • 7
  • 21