# 不能上传文件夹,源码里面写着上传文件有可能会发生错误
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