Electron下使用samba相关问题记录

概述

笔者准备在Electron框架下使用samba-client进行远程交互,结果发觉存在基本的使用问题,连基本的连接都有问题:samba-client 代码地址

猜测可能与samba-server端使用版本有关。(难道samba-client不支持samba2?貌似没看到代码文档说明。)

smb2 (bchelli/mode-smb2)

bchelli/mode-smb2 Github地址
该库较为久远,所支持也很有限,尤其是其支持的uri地址,都比较像Windows专用,果然在测试了某些基本接口后发现如下类似问题:
smb2 read P3 err = Error: STATUS_ACCESS_DENIED (0xC0000022) : {Access Denied} A process has requested access to an object but has not been granted those access rights.

在github上找到了对应issue:https://github.com/bchelli/node-smb2/issues/17

This issue seems to be fixed here:
https://github.com/Node-SMB/marsaud-smb2 at least it worked with
“readdir” for me. For reference: Node-SMB#18 The docs show var SMB2 =
require(‘smb2’); but I had to use var SMB2 = require(‘@marsaud/smb2’);
to reference the package.

@marsaud/smb2 (Node-SMB/marsaud-smb2)

Node-SMB/marsaud-smb2 Github地址
该库从 bchelli/mode-smb2 Github地址 fork而来,作者近期还在维护,可靠度还是蛮高的。

使用如下指令安装即可:

npm install -g @marsaud/smb2@latest

简单测试了下对应的读取文件、下载文件、上传文件、创建目录等基本功能,还是比较靠谱的。唯独在测试上传文件(createWriteStream)时,总是会出现如下报错:

smb2 createWriteStream err = Error: STATUS_ACCESS_DENIED (0xC0000022): {Access Denied} A process has requested access to an object but has not been granted those access rights.

检查后发现,服务器中已经存在对应文件时,则会出现上述问题。经测试,该库基本功能完善,而且还提供了一些更灵活的功能:

smb2Client.open('path\\to\\the\\file', function(err, fd) {
  if (err) throw err;

  smb2Client.read(
    Buffer.alloc(10), // buffer where to store the data
    0, // offset in the buffer
    10, // number of bytes to read
    0, // offset in the file
    function(err, bytesRead, buffer) {
      smb2Client.close(fd, function() {});

      if (err) throw cb(err);
      console.log(bytesRead, buffer);
    }
  );
});
This API is modeled after Node's fs module.

Note: be careful of autoCloseTimeout with this process as it is not intended to cover multiple method calls, you should set it to 0 and manually disconnect().

可以根据实际需求自行扩展。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Luppiter.W

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值