Hello, there is a remote Linux server on which files are stored, approximately along the following path: /opt/glassfish/blabla/файлы.

On another computer site on php, on the codeigniter framework. I need to do something so that when I click on the link and hit the controller, I can download the file from the first server.

I was told that I need to make links to files and store them in the database. But I don’t quite understand how these links should look like, how to create them. To get to the first server, you need a login and password, should they be in the link?

My searches in Google constantly end around the helpers "download" and "ftp", but the first one allows you to download something from your machine, and the second - upload something to a remote server, or change something there.

Could you explain to me about the links?

  • First, decide on what protocol you are going to collect files from the server. There are many options: ftp, http, etc. - KEPZ

2 answers 2

I figured out my problem, at the time I asked questions I didn’t understand what I needed, so I asked the question badly and got bad answers. On Linux server, in order to download files from it, you had to write an interface that would send files via http or ftp protocol.

In my case it turned out a servlet written in JAVA ...

 @WebServlet(name = "getExcelFile", urlPatterns = {"/getExcelFile"}) public class GetExcelFile extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fileName = request.getParameter("filename"); // полный путь к файлу String fileNameFullPath = ExcelPath.EXCEL_PATH.concat(fileName); if ((new File(fileNameFullPath)).exists()) { response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=".concat(fileName) ); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream()); FileInputStream fis = new FileInputStream(fileNameFullPath)) { int c; while ((c = fis.read()) != -1) { bos.write(c); } bos.flush(); } } } } 

Next, go to http: // (IP): (PORT) / (Project_name) / getExcelFile? Filename = 'enter the name of the file and, if it exists, it will be available for download.

    Tried to create a server on the first computer and download from it? For example, nginx or apache.
    Then for downloading the path will be something like <внешний ip>/имя файла , and internal <..>/public

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • In order to give files there are two types of servers: http - apache (or nginx) and file - FTP. After that, it will be possible to obtain an external link to the file of the type xxxx.xxxx.xxxx.xxxx / < directory name > / <file name> (for the http version). - Idushii
    • * Two of the most famous - Idushii