zoukankan      html  css  js  c++  java
  • python sftp 创建文件夹,上传文件,下载文件

     # 不能上传文件夹,源码里面写着上传文件有可能会发生错误
    1
    import paramiko # 用于调用scp命令 2 import datetime

    5 HOST = 'host地址' 6 PORT = 22 7 USERNAME = '用户名' 8 PASSWORD = '密码' 9 PATH = '路径'
    # 当天日期
    10 TODAY = datetime.datetime.now().strftime('%Y%m%d') 11 12 13 def create_files(): 14 transport = paramiko.Transport((HOST, PORT)) # 获取Transport实例 15 transport.connect(username=USERNAME, password=PASSWORD) # 建立连接 16 sftp = paramiko.SFTPClient.from_transport(transport) 17 18 # 判断当前日期文件夹是否存在 19 is_existence = True if TODAY in sftp.listdir(PATH) else False 20 21 if not is_existence: 22 # 创建文件夹 23 sftp.mkdir(PATH + TODAY)
    25 # 上传 26 # sftp.put("C:/Users/Admin/Desktop/Rsa.py", "/home/rzbsftp/RSa.py") 27 # 下载 28 # sftp.get("/home/rzbsftp/1586395726920.xlsx", "F:/222/1586395726920.xlsx") 32 sftp.close() 33 transport.close() 40 41 if __name__ == '__main__': create_files() 44
  • 相关阅读:
    Python_Note_08Day 9_HTML
    Python_Note_08Day 6_Bastion Host_Paramiko_SSH
    Python_Note_08Day 5_Module
    Python_Note_Day 11_Mysql02_Python MySQL API
    Python_Note_Day 11_Mysql
    Python_Data_Analysis_01
    485. Max Consecutive Ones
    498. Diagonal Traverse
    500. Keyboard Row
    481. Magical String
  • 原文地址:https://www.cnblogs.com/pythonSF/p/13035617.html
Copyright © 2011-2022 走看看