Linux访问Windows的共享目录,pysmb(参数remote_name定义)

本文介绍了三种不同的方法来访问远程文件:使用Windows下的netuse命令、利用Linux的sudomount命令挂载远程共享目录以及通过Python的pysmb库进行文件操作。文章详细解释了各方法的适用场景及限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方案一

net use 此命令只在Windows下面可用。

方案二

sudo mount -t cifs -o username=administrator,password=password //remote_share_server_ip/share_dir ./data
这条命令必须使用root权限,对于不能使用root权限的应用无法实现。没有sudo会报错:
mount: only root can use "--options" option

方案三

Python包pysmb

def check_unc_source(self, unc_path, username, password):
    conn = SMBConnection(username, password, '', remote_name, is_direct_tcp=True)
    result = conn.connect('remote_share_server_ip', 445)
    with open("local_file", "wb") as local_file:
        conn.retrieveFile("share_dir", "file", local_file)

SMBConnection第4个参数,remote_name:

The NetBIOS machine name of the remote server.
On windows, you can find out the machine name by right-clicking on the “My Computer” and selecting “Properties”.
This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.

实际上可以填写Windows远程共享目录所在服务器的IP地址,即和conn.connect的第一个参数remote_share_server_ip相同,如果为空,会报错:
smb.smb_structs.OperationFailure: Failed to retrieve [file] on share_dir: Unable to connect to shared device

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值