python3 访问windows共享目录

1、安装pysmb包

pip install pysmb

2、连接共享目录

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from smb.SMBConnection import SMBConnection

server_ip = "10.0.0.1"                         #共享目录主机IP地址
username = "xxxxx"                             #本机用户名
password = "xxxxxx"                            #本机密码
my_name = "本机域名"                            #计算机属性中域名
remote_name = "abc-infoserver"                 #远端共享文件夹计算机名
conn = SMBConnection(username, password, my_name, remote_name, is_direct_tcp = True)    #is_direct_tcp=True,默认为当direct_tcp=True时,port需要445。当它是False时,端口应该是139
assert conn.connect(server_ip, 445)
sharelist = conn.listPath("00-访问指南","/")
for i in sharelist:
    print (i.filename)

 

相关文章:

  • 2022-03-08
  • 2021-10-14
  • 2021-10-20
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2021-08-01
  • 2022-03-01
  • 2021-08-12
  • 2022-12-23
  • 2021-12-24
  • 2021-08-17
相关资源
相似解决方案