首页 > 解决方案 > 如何将文件从一台服务器下载到另一台服务器

问题描述

我正在尝试将文件从一台服务器下载到另一台服务器,例如假设我有 2 个服务器 1.api 服务器和 2.test 服务器

在测试服务器

downloadFile(req, res) {
  let file = path.join(__dirname, "../config/config.js");
  res.status(200).send("http://ip-address:port" + file);
}

在 api 服务器中

  const http = require('http');
  const path = require('path'); 
  HttpDownload(req,res) {

        let file = fs_file.createWriteStream(path.join(__dirname, "..", "..", "temp", "output.js"));
        http.get(url-to-test-server, function (response) {
            response.on('data', function (chunk) {
                file.write(chunk)
            })
            response.on('end', function () {
                console.log('download file completed.')
                res.download(path.join(__dirname, "..", "..", "temp", "output.js"))
            })
        })
}

谁能建议我我做错了什么?预先感谢。

标签: javascriptnode.jsexpress

解决方案


推荐阅读