smb

# -*- coding: utf-8 -*-


__author__ = 'stephen'
#smb://192.168.0.30/product_public/休闲游戏/产品资料/产品目录/Yurudora(悠悠世界树)/原厂资料/文件/制作总结_0811_tmp2.xlsx
import os
from smb.SMBConnection import SMBConnection
from nmb.NetBIOS import NetBIOS
import sys


def getBIOSName(remote_smb_ip, time_= 30):
    try:
        bios = NetBIOS()
        srv_name = bios.queryIPForName(remote_smb_ip, timeout = time_)
    except:
        print >> sys.stderr, "Looking up time out"
    finally:
        bios.close()
        return srv_name


def get_script_file():


    remoteIP = "192.168.0.30"


    conn = SMBConnection('anonymous', '', 'xiaoqindeMac-mini.local', '', use_ntlm_v2 = True)
    assert conn.connect(remoteIP, 139)
    sharelist = conn.listShares()#列出共享目录
    for i in sharelist:
        print i


    rootDir = os.getcwd() # 文本放到ccb一个文件夹下面文件夹下面
    file_obj = open(rootDir + os.sep + "src.xlsx", 'w')


    srv_name = getBIOSName(remoteIP)
    print  srv_name
    file_attributes, filesize = conn.retrieveFile("product_public",
                                                  '/休闲游戏/产品资料/产品目录/Yurudora(悠悠世界树)/原厂资料/文件/制作总结_0811_tmp2.xlsx'.decode("utf8"),
                                                  file_obj)
    file_obj.close()


get_script_file()

你可能感兴趣的:(smb)