有谁知道nodejs如何实现远程访问共享文件,我写了如下代码:
发布于 11 年前 作者 miracle123 11562 次浏览 最后一次编辑是 8 年前

有谁知道如何实现远程访问共享文件,我写了如下代码: var sourcefile = ‘smb://xindun;username:password@172.16.21.196/Files/svn.txt’; fs.readFile(sourcefile, ‘utf-8’, function(err, data){ if(err) throw err; console.log(data) ; }); 但是运行报如下错误enter image description here

6 回复

不知道你的SMB协议是什么东西,访问局域网可以用child_process

var spawn = require(‘child_process’).spawn;

var auth = spawn(‘net’, [‘use’, ‘\\172.16.21.196’, ‘/user:username’, ‘password’]);

auth.stdout.on(‘data’, function(data){ console.log(‘执行!’); });

auth.stderr.on(‘data’, function(data){ console.log(‘错误!’); });

auth.on(‘exit’, function(data){ console.log(‘退出!’); });

我按照你的代码执行了,但是出现如下enter image description here

我执行的代码如下

var spawn = require(‘child_process’).spawn;

var auth = spawn('net ', ['use ', ‘//172.16.21.196/Files’, ‘/user:xindun/zhangdandan’, ‘Luckywillyou123’]);

auth.stdout.on(‘data’, function(data){ console.log(‘执行!’); });

auth.stderr.on(‘data’, function(data){ console.log(‘错误!’); });

auth.on(‘exit’, function(data){ console.log(‘退出!’); });

这个net use不是磁盘映射的功能吗,这样能在我本地打开那个共享文件夹吗

fs 还能读取远程文件?

想知道怎么实现读取磁盘目录文件,创建,删除之类的功能

不知道楼主的问题解决了没 我现在也遇到这个问题

回到顶部