pyton 模块之 pysmb 文件上传(windows)


#!/usr/bin/env python
#coding:utf-8

from smb.SMBConnection import SMBConnection
from nmb.NetBIOS import NetBIOS
import os,sys
def getBIOSName(remote_smb_ip, timeout=30):
    try:
        bios = NetBIOS()
        srv_name = bios.queryIPForName(remote_smb_ip, timeout=timeout)
    except:
        print >> sys.stderr, "Looking up timeout, check remote_smb_ip again!!"
    finally:
        bios.close()
        return srv_name
serverip='10.0.30.174'
conn = SMBConnection('guest', '', 'any',getBIOSName(serverip)[0], use_ntlm_v2 = True)
assert conn.connect(serverip, 139) #smb服务器地址
temdir='/'
dir=os.path.join('/','public')
f = open('D:/test4.txt', 'rb')
conn.storeFile('Users',os.path.join(dir,'test1.txt'),f)
f.close()
下载可参考linux版本的
windows和linux区别在于netbios

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM