1、使用python连接smb服务器,进行上传下载操作
# -*- coding: utf-8 -*-
#导入smb库
from smb.SMBConnection import SMBConnection
import os
from datetime import datetime
host = "192.168.16.243"
username = "smb1"
password = "topwalk"
conn = SMBConnection(username, password, "", "", use_ntlm_v2=True)
result = conn.connect(host, 445) # smb协议默认端口445
print("smb连接成功")
start = datetime.now()
print(f"脚本开始运行时间{start}>秒")
for dirpath,dirnames,filenames in os.walk('/ssdraid/ssdftp/ssdftp4'):
file_count = len(filenames)
print(file_count)
counts = len(filenames) + 1
for i in range(1,counts):
#print("/ssdraid/ssdftp/ssdftp7/ftp_1k_%s.txt" % i)
localFile = open("/ssdraid/ssdftp/ssdftp4/ftp_1k_%s.txt" % i,"rb")
conn.storeFile("smb1","ftp_1k_%s.txt" % i,localFile)
localFile.close()
print("上传成功")
start = datetime.now()
print(f"脚本运行结束时间{start}>秒")
网友评论