1 Star 0 Fork 0

桔子/sgcard-server-publish-tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sftp.py 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
# Author : Li Jixue
# Date : 2017/6/27
# Description: sftp下载上传
# ------------------------------------------------------------------------------
import os
import paramiko
def ssh(host, port, username, password, cmd):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
stdin, stdout, stderr = ssh.exec_command(cmd, get_pty=True)
result = stdout.readlines()
ssh.close()
return result
def download(host,port,username, password,local, remote):
sf = paramiko.Transport((host, port))
sf.connect(username = username,password = password)
sftp = paramiko.SFTPClient.from_transport(sf)
if os.path.isdir(local):#判断本地参数是目录还是文件
for f in sftp.listdir(remote):#遍历远程目录
print(f)
sftp.get(os.path.join(remote+f), os.path.join(local+f))#下载目录中文件
else:
sftp.get(remote,local)#下载文件
sf.close()
def sftp_upload(host, port, username, password, local, remote):
sf = paramiko.Transport((host, port))
sf.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(sf)
# 判断本地参数是目录还是文件
if os.path.isdir(local):
# 遍历本地目录
for f in os.listdir(local):
# 上传目录中的文件
sftp.put(os.path.join(local+f), os.path.join(remote+f))
else:
# 上传文件
sftp.put(local, remote + os.path.basename(local))
sf.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/juzzi/sgcard-server-publish-tool.git
git@gitee.com:juzzi/sgcard-server-publish-tool.git
juzzi
sgcard-server-publish-tool
sgcard-server-publish-tool
master

搜索帮助