upload文件
2021/8/26 6:06:25
本文主要是介绍upload文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import paramiko import datetime import os hostname = '168.0.0.1' username = 'root' password = '123457' port = 22 def upload(local_file, remote_path): try: t = paramiko.Transport((hostname, port)) t.connect(username=username, password=password) sftp = paramiko.SFTPClient.from_transport(t) print('开始上传文件%s ' % datetime.datetime.now()) try: sftp.put(local_file, remote_path) except Exception as e: sftp.mkdir(os.path.split(remote_path)[0]) sftp.put(local_file, remote_path) print("从本地: %s 上传到: %s" % (local_file, remote_path)) print('文件上传成功 %s ' % datetime.datetime.now()) t.close() except Exception as e: print(repr(e)) if __name__ == '__main__': local_file = r'/home/shl/dataETL/timings/words/word_pos.csv' remote_path = os.path.join('/home/', "word_pos.csv") upload(local_file, remote_path)
这篇关于upload文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Mybatis官方生成器资料详解与应用教程
- 2024-11-26Mybatis一级缓存资料详解与实战教程
- 2024-11-26Mybatis一级缓存资料详解:新手快速入门
- 2024-11-26SpringBoot3+JDK17搭建后端资料详尽教程
- 2024-11-26Springboot单体架构搭建资料:新手入门教程
- 2024-11-26Springboot单体架构搭建资料详解与实战教程
- 2024-11-26Springboot框架资料:新手入门教程
- 2024-11-26Springboot企业级开发资料入门教程
- 2024-11-26SpringBoot企业级开发资料详解与实战教程
- 2024-11-26Springboot微服务资料:新手入门全攻略