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)