Question

I've written an ftp crawler to download specific files. It works up until it finds the specific file it wants to download, and then it throws this error:

ftplib.error_perm: 550

The file exists in my download folder, but the size of the file is 0 kb. Do I need to convert something in order to get it to download?. I can access the ftp manual and download the file without any problems, so don't think it's the login part (unless there's different ways of logging in??)

Here's my code:

import ftplib
import re
import os


class Reader:

def __init__(self):

    self.data = ""

def __call__(self,s):

    self.data += s + "\n"

ftp = ftplib.FTP("my_ftp_server")

ftp.login()

r = Reader()

ftp.dir(r)

def get_file_list(folder):



    r = Reader()

    ftp.dir(folder, r)

    print ("Reading folder",folder)


    global tpe
    global name
    for l in r.data.split("\n"):

        if len(l) > 0:
            vars = re.split("[ ]*", l)
            tpe = vars[2]
            name = vars[3]
        if tpe == "<DIR>":

            get_file_list( folder + "/" + name )
        else:
            print (folder + name)
        for name in folder:
            if vars[3].endswith(('501.zip','551.zip')):
                if os.path.exists('C:\\download\\' + vars[3]) == False:
                    fhandle = open(os.path.join('C:\\download\\', vars[3]), 'wb')
                    print ('Getting ' + vars[3])
                    ftp.retrbinary('RETR ' + vars[3], fhandle.write)
                    fhandle.close()
                elif os.path.exists(('C:\\download\\' + vars[3])) == True:
                    print ('File ', vars[3], ' Already Exists, Skipping Download')

print("-"*30)
print ("Fetching folders...")

get_file_list("")
Was it helpful?

Solution

Your code is probably OK.

FTP error 550 is caused by a permission issue on the server side.

This error means 'Requested action not taken. File unavailable (e.g., file not found, no access).', as you can find out here on Wikipedia

If you expect to have access to it, you should contact the sysadmin to rectify the file permission.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top