In node.js I am trying to watch and read a text file on filechange.For this, I am using below code and it is working absolutely fine.
var fs = require('fs'),bite_size = 256,readbytes = 0,file;
fs.open('testread.txt', 'r', function(err, fd) {
file = fd; //readsome();
var func = (function readsome() {
var stats = fs.fstatSync(file); // yes sometimes async does not make sense!
if(stats.size<readbytes+1) {
setTimeout(readsome, 1000);
}
else {
fs.read(file, new Buffer(bite_size), 0, bite_size, readbytes, function (err, bytecount, buff) {
console.log(buff.toString('utf-8', 0, bytecount));
readbytes+=bytecount;
process.nextTick(readsome);
});
}
})();
});
But this works only for local file and now I need to read text file from remote server ( may be linux or windows) in same way.
Please help , how can I use remote server login information like below
IP address = "XXX.XXX.XX.XX";,
username = username,
password = password,
filepath = "/root/testread.txt" or "D:\testread.txt"
and read the data from text file present at filepath in remote server.
fs uses the local filesystem. To access remote files you need to use some network protocol (NTFS for Windows and ssh or ftp for linux for example) Those protocols expose files to remote access, you cannot access the filesystem of a remote host not using them
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.