简体   繁体   English

Python FTP下载550错误

[英]Python FTP download 550 error

I've written an ftp crawler to download specific files. 我写了一个ftp搜寻器来下载特定文件。 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. 该文件存在于我的下载文件夹中,但文件大小为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??) 我可以访问ftp手册并下载文件,没有任何问题,所以不要以为它是登录部分(除非有不同的登录方式?)

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("")

Your code is probably OK. 您的代码可能没问题。

FTP error 550 is caused by a permission issue on the server side. FTP错误550是由服务器端的权限问题引起的。

This error means 'Requested action not taken. 此错误表示“未执行请求的操作。 File unavailable (eg, file not found, no access).', as you can find out here on Wikipedia 文件不可用(例如,文件未找到,无法访问)。,如您在Wikipedia上所见

If you expect to have access to it, you should contact the sysadmin to rectify the file permission. 如果您希望可以访问它,则应联系sysadmin以更正文件权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM