简体   繁体   中英

Getting pictures from an ftp server(locally) to display on website

I got my pictures on an ftp server, on my network, which i want to display on my website.

How can that be done?

Earlier i used ("/Boats/{BoatId}/{ImageId} + "." + {ImageExtension") but now i have my pictures on \\\\ftplocation\\files\\boatcompany\\boats\\

I tried the following: (Works with the url above).

ImageUrl='<%# String.Format(@"\\ftp\files\boatcompany\boats\{0}\thumbnails\{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>' />

In addition to Max's answer I wanted to add a third solution that works with both private and public ftp servers (and anything else really).

What you need to do is use your application as a proxy for the ftp.

  • Add a page, f.ex. "getimage.aspx" which accept arguments, f.ex. id's of the image
  • From the page, when called, response with header setting (mime-type etc.) (hold)
  • Connect to ftp server, log in if needed and stream the file requested.
  • Forward the content of that stream to your page's stream (response stream) and close.

Then you can do this (line breaks to make it more readable):

ImageUrl = '<%# 
    String.Format(@"/getimage.aspx?boatid={0}&imageid={1}&extension={2}", 
                  Eval("BoatId"), 
                  Eval("Image.ImageId"), 
                  Eval("Image.Extension")) %>'

For FTP you can use the built-in capabilities in .net or use a third-party extension such as Rebex-FTP which makes streaming files from ftp a walk in the park.

Using a page to retrieve pictures this way makes it capable of obtaining images from various sources, not just ftp, at the same time keeping it transparent for the user.

Because of security issues browsers will never load any resources (including images) from local storage. So, URLs like \\\\server\\myfile.jpg or file:///server/myfile.jpg will never be loaded from an Internet web site. That's why your code doesn't work.

You have two options:

1 . If you ftplocation is a real FTP server and it can be accessed from the outer world with a real FTP URL, you can use this code:

ImageUrl='<%# String.Format(@"ftp://ftp.server.com/files/boatcompany/boats/{0}/thumbnails/{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>

2 . You can create a virtual subfolder in IIS inside your web project, call it Boats and point that virtual folder to \\\\ftplocation\\files\\boatcompany\\ folder. Then in your code use just this (pretty much the same code as you used before you've got the FTP):

ImageUrl='<%# String.Format(@"/Boats/{0}/thumbnails/{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>

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