-1

I'm trying to use a script that would automate deletion of images from a website using FTP and Python. My script is as follows:

import ftplib
session = ftplib.FTP('#server','#user','#pw')
session.delete("#path_to_file_on_webserver")

This is generating the following error: error_perm: 550 Could not delete "#file_to_path_on_webserver": No such file or directory.

The path to the file is definitely correct and copying that to the browser takes me to the image. I should add that I'm using what I believe to be the full path - "http://websitename.com/pathstoimage/image.jpg"

I spoke to my webhost who changed permissions to the image folder to 777 and to the files as 777 but I'm still getting that error. What's stranger is that I can modify the script to upload images to the server and that works okay, so I'm at a bit of a loss as to what's gone wrong. Any suggestions please?

Thanks

alexisdevarennes
  • 5,437
  • 4
  • 24
  • 38
Situl
  • 40
  • 8
  • run session.dir() before just to confirm the path – Ramon Medeiros Jan 22 '20 at 09:21
  • I'm not sure what that's supposed to do... I've added it to my code just after the 2nd line and printed the results out. It's just printing out a table of what looks to be previous FTP connections but nowhere in this table can I find the path. – Situl Jan 22 '20 at 09:28
  • 2
    HTTP URL has nothing to do with FTP. Can you delete that file using any (GUI) FTP client? Use the path that you see in the FTP client. – Martin Prikryl Jan 22 '20 at 11:51
  • Yeah I've done this now, and realised that my FTP login details are taking me straight to the images folder. As such I don't need to specify a path to the image, just the image name and the deletion works. Thanks – Situl Jan 24 '20 at 05:18

1 Answers1

0

Thanks to Martin Prikryl for the suggestion. The issue was caused by my FTP logon details root directory being my image folder that I wanted to delete. As such, specifying a path when already in the correct folder was resulting in me being unable to find the file. All I needed to do was provide the image name and it worked.

Situl
  • 40
  • 8