0

I want to delete files from the server using the Pycurl or Python request method. I have a list of file names and I want to delete all files from OVH server by comparing name with the List items. I am using OVH cloud API.

this is the code for delete one file from the server. I want to delete multiple files. how do do this ?

file_path = '/home/u_file.txt'

url url ='https://'+OVH_ENDPOINT+'+filename

headers = {
    'content-type': "multipart/form-data; boundary=---- 
WebKitFormBoundary7MA4YWxkTrZu0gW",
    'X-Auth-Token': ""+ovhToken+"",
    'Cache-Control': "no-cache"
    }
r = requests.delete(url, headers=headers)
n = os.write(sys.stdout.fileno(), r.content)
  • Why not just add a loop and run the delete code multiple times? You could use the if statement to check if filename matches those present in your list. You need to find the method that lists all of the filenames present on the server. I have used this method with pysftp and am unfamiliar with the library you are using but this logic should work. – Ninad Gaikwad Sep 14 '18 at 07:18
  • @ninad I used loop already but if I use the loop then I have to call the API for every file deletion. Like if i have 1000 files on List then i have to call the API 1000 times. which is a very slow method. – Nauman Ali Sep 14 '18 at 12:25
  • Can you share the code you used with pysftp @Ninad – Nauman Ali Sep 14 '18 at 12:26
  • I didn't use an api. I connected to server using pysftp and then just recursively deleted. I do not believe there is any other way to delete multiple files selectively though. You can delete entire directory but not selected files. – Ninad Gaikwad Sep 14 '18 at 12:34
  • Thankyou @ninad – Nauman Ali Sep 14 '18 at 12:44

0 Answers0