0x00 批量上传脚本

通过DS的文件上传接口,制作批量上传文件的脚本。init方法中的token需要改为自己的token,DS在导航安全中心->令牌管理中可以创建token。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import requests
import json

class UploadScript2DS:
def __init__(self, local_path):
self.headers = {
'token':'xxxxx'
}
self.host = "http://hadoop003:12345"
self.local_path = local_path


def upload_signle_dir(self, pid, current_dir,decs=None):
url = self.host + "/dolphinscheduler/resources"

payload = {
'type': ' FILE',
'pid': pid,
'currentDir': current_dir,
'description': decs
}

for file in os.listdir(self.local_path):
file_path = os.path.join(self.local_path, file)

if not file.endswith('.sql'):
continue

payload['name'] = file

files=[
('file',(file,open(file_path,'rb'),'application/octet-stream'))
]

response = requests.request("POST", url, headers=self.headers, data=payload, files=files)
print(response.status_code)

if __name__ == '__main__':
dir_path = r"F:\workspace\cityoprs\dws\dws_cityopr_cctd_mthy"
upload = UploadScript2DS(dir_path)

upload.upload_signle_dir(258, '/cityopr/cctd/dws/dws_cityopr_cctd_mthy', '煤炭行业')

0x01 参数说明

批量上传文件脚本,记得修改:

  • dir_path 你本地的文件路径
  • pid (258) 修改为父目录的ID
  • current_path 修改为父目录的全路径