windows上传本地文件值Linux服务器: #!/usr/bin/env python # coding: utf-8 import paramiko import datetime import os import tkinter.messagebox class UploadFile: def __init__(self): self.hostname = 'ip地址' self.username = '用户名' self.password = '密码' self.port = 22 try: self.conn = paramiko.Transport(self.hostname, self.port) self.conn.connect(username=self.username, password=self.password) self.sftp = paramiko.SFTPClient.from_transport(self.conn) except Exception as e: tkinter.messagebox.showerror("FishC Demo", "连接服务器出错!") def upload(self,local_path, remote_path): print('开始上传文件时间: %s ' % datetime.datetime.now()) #判断是否是文件夹 if os.path.isdir(local_path): for root, dirs, files in os.walk(local_path): for filespath in files: #获取本地将要上传的文件列表 local_file = os.path.join(root, filespath) # print('本地文件全路径: %s' % (local_file)) #远程文件服务器地址 remote_file = os.path.join(remote_path, filespath) # print("全程文件全路径:" + remote_file) try: self.sftp.put(local_file, remote_file) except Exception as e: print("上传异常: %s" % (e)) else: try: # print('本地文件全路径: %s' % (local_path)) self.sftp.put(local_path, remote_path) # print("全程文件全路径:" + remote_path) except Exception as e: print("上传异常: %s" % (e)) print('全部文件上传完成时间: %s ' % datetime.datetime.now()) self.conn.close()
windows上传本地文件值Linux服务器
最新推荐文章于 2024-05-07 15:00:55 发布