远程访问斐讯天天链N1(python源码)写的不好 仅仅为了实现功能

本文展示了如何使用Python的smb库连接并管理斐讯天天链N1的共享文件。通过创建一个名为ConnectSamba的类,实现了文件的下载、上传、删除、重命名以及目录的浏览等功能。
摘要由CSDN通过智能技术生成
from smb.SMBConnection import SMBConnection
from tkinter import *
import tkinter.filedialog as filedialog




class ConnectSamba():

    def __init__(self):
        #self.username = 'root'
        #self.password = 'xxxxxxxx'
        self.my_name = 'anonymous'
        self.domain_name = ''
        #self.remote_smb_IP = 'xxx.xxx.xxx.xxx'
        #self.port = 1139
        self.dir = ''
        self.display_path = ''

    def downloadFile(self):
        try:
            conn = SMBConnection(self.username.get(), self.password.get(), self.my_name, self.domain_name, use_ntlm_v2=True)
            conn.connect(self.remote_smb_IP.get(), int(self.port.get()))
            file_obj = open(ml.get(ml.curselection()), 'wb')
            conn.retrieveFile(self.dir, self.display_path + '/' + ml.get(ml.curselection()), file_obj)
            conn
            file_obj.close()
            return True
        except:
            return False

    def uploadFile(self):
        filetypes = [
            ("All Files", '*'),
            ("Python Files", '*.py', 'TEXT'),
            ("Text Files", '*.txt', 'TEXT'),
            ("Exe Files", '*.exe', 'TEXT')]
        fobj = filedialog.askopenfile(filetypes=filetypes)
        if fobj:
            self.upload_path = fobj.name
            a = len(self.upload_path.split('/'))
            try:
                conn = SMBConnection(self.username.get(), self.password.get(), self.my_name, self.domain_name,
                                     use_ntlm_v2=True)
                conn.connect(self.remote_smb_IP.get(), int(self.port.get()))
                file_obj = open(self.upload_path, 'rb')
                conn.storeFile(self.dir, self.display_path + '/' + self.upload_path.split('/')[a - 1], file_obj)
                file_obj.close()
                return True
            except:
                return False
        else:
            pass

    def display(self, a):
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值