Python FTP下载550错误 [英] Python FTP download 550 error

查看:102
本文介绍了Python FTP下载550错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个ftp搜寻器来下载特定文件.它会一直工作到找到要下载的特定文件,然后引发此错误:

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

该文件存在于我的下载文件夹中,但文件大小为0 kb.我需要转换某些东西才能下载吗?我可以访问ftp手册并下载文件,没有任何问题,所以不要以为它是登录部分(除非有不同的登录方式?)

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??)

这是我的代码:

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

推荐答案

您的代码可能还可以.

FTP错误550是由服务器端的权限问题引起的.

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

此错误表示未执行请求的操作.文件不可用(例如,文件未找到,无法访问).",您可以在Wikipedia上的中找到

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.

这篇关于Python FTP下载550错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆