简体   繁体   中英

FTP transfer via ASP.net page

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM