Skip to content Skip to sidebar Skip to footer

Is There Anyway To Copy/upload/edit A File With Javascript?

I have two servers, Server1 & Server2. I want to copy a file from Server1 to Server2 with JavaScript. Is this possible? If so, how? For example, last week I used 'wget' command

Solution 1:

i don't know the full specifications for the task at hand, but you could look into using Node.js to assist with your issue. here's a quick repo that might help repo or you could use this snippet i took from similar post:

var http = require('http');
var fs = require('fs');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/',
  {'host': 'www.google.com'});
 request.end();
 out = fs.createWriteStream('out');
 request.on('response', function (response) {
 response.setEncoding('utf8');
 response.on('data', function (chunk) {
  out.write(chunk);
  });
});

i hope this helps, and here's the original post

Solution 2:

Nope. You can't access disk from JavaScript. Just for a moment think of security problems it can bring with itself. I simply create a web page, and when you visit it, I upload all the images of your girlfriend and publish them (just kidding, but that's the security problem it poses).

However, JavaScript can access files on some scenarios:

  1. When user selects some files using <input type='file' /> element
  2. Using HTML5's offline-storage (I guess this one, not sure).

However, if you want, you can use Node.js to do that. However, this is a server-side stuff.

Post a Comment for "Is There Anyway To Copy/upload/edit A File With Javascript?"