简体   繁体   English

使用 python ftplib 下载但得到 ConnectionRefusedError: [Errno 111] Connection refused

[英]use python ftplib downloading but get ConnectionRefusedError: [Errno 111] Connection refused

I was trying use ftplib to download from a FTP server, but I get ConnectionRefusedError: [Errno 111] Connection refused This is my code:我正在尝试使用 ftplib 从 FTP 服务器下载,但出现ConnectionRefusedError: [Errno 111] Connection refused这是我的代码:

import os
import sys
import configparser
import socket

def downloadfile(downftp, remotepath,localpath):
    bufsize=1024
    fp = open(localpath,'wb')     
    downftp.set_debuglevel(2)
    downftp.retrbinary('RETR ' + remotepath, fp.write, bufsize)
    fp.close()   
    
def ftpconnect(host,username,password):
    ftp = FTP()
    ftp.connect(host=host,port=10022)
    ftp.login(username, password)
    return ftp

def uploadfile(ftp,remotepath, localpath):
    bufsize=1024
    fp=open(localpath,'rb')       
    ftp.set_debuglevel(0)
    ftp.storbinary('STOR ' + remotepath, fp, bufsize)
    fp.close()
conftp = ftpconnect('42.*.**.201','cityof********.****erver','COU***123')
downloadfile(conftp,'/world/datapacks/sys/data/pgdc/functions/food.mcfunction','food.mcfunction')

All error:所有错误:

  File "<pyshell#7>", line 1, in <module>
    ftp.dir()
  File "/usr/lib/python3.6/ftplib.py", line 575, in dir
    self.retrlines(cmd, func)
  File "/usr/lib/python3.6/ftplib.py", line 468, in retrlines
    with self.transfercmd(cmd) as conn, \
  File "/usr/lib/python3.6/ftplib.py", line 399, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python3.6/ftplib.py", line 361, in ntransfercmd
    source_address=self.source_address)
  File "/usr/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

I tried ftp.set_pasv(True) ,it shows the same error ConnectionRefusedError: [Errno 111] Connection refused我试过ftp.set_pasv(True) ,它显示相同的错误ConnectionRefusedError: [Errno 111] Connection refused

I tried ftp.set_pasv(False) , and it hanging on我试过ftp.set_pasv(False) ,它挂在

...
*cmd* 'RETR /world/datapacks/sys/data/pgdc/functions/food.mcfunction'
*put* 'RETR /world/datapacks/sys/data/pgdc/functions/food.mcfunction\r\n'
*get* '150 Opening ASCII mode data connection\n'
*resp* '150 Opening ASCII mode data connection'

Help please.Thank you.请帮助。谢谢。

Are you able to successfully connect to the ftp server from command line ie without the python code?您是否能够从命令行成功连接到 ftp 服务器,即没有 python 代码? I think this should be first step to check if Connection is Refused by ftp or something wrong with python code.我认为这应该是检查连接是否被 ftp 拒绝或 python 代码有问题的第一步。

 ftp = FTP(host=ftp_host, user=ftp_user,passwd=ftp_pass)
 ftp.login()

Is your upload working fine?你的上传工作正常吗?

暂无
暂无

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

相关问题 Ftplib ConnectionRefusedError: [Errno 111] 连接被拒绝 (python 3.5) - Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5) ConnectionRefusedError:[Errno 111]连接被拒绝 - ConnectionRefusedError: [Errno 111] Connection refused python 套接字返回 ConnectionRefusedError: [Errno 111] 连接被拒绝 - python socket return ConnectionRefusedError: [Errno 111] Connection refused python-valve rcon minecraft&#39;ConnectionRefusedError:[Errno 111]连接被拒绝&#39; - python-valve rcon minecraft 'ConnectionRefusedError: [Errno 111] Connection refused' Python ConnectionRefusedError:[Errno 111] Docker 容器上的连接被拒绝 - Python ConnectionRefusedError: [Errno 111] Connection refused on Docker container ConnectionRefusedError: [Errno 111] 连接被拒绝- Mlrun - ConnectionRefusedError: [Errno 111] Connection refused- Mlrun Flask+requests API ConnectionRefusedError: [Errno 111] 连接被拒绝 - Flask+requests API ConnectionRefusedError: [Errno 111] Connection refused 在Python(多处理)中正确酸洗和取消代理对象? “ConnectionRefusedError:[Errno 111] 解压时连接被拒绝” - Properly pickling and unpickling proxy objects in Python (multiprocessing)? "ConnectionRefusedError: [Errno 111] Connection refused while unpickling" ConnectionRefusedError:[Errno 111] 笔记本电脑和树莓派之间使用 python 连接被拒绝 - ConnectionRefusedError: [Errno 111] Connection refused between laptop and raspberry pi using python python 发送电子邮件 - ConnectionRefusedError: [Errno 111] 连接被拒绝。 请提出一些想法 - python sending email - ConnectionRefusedError: [Errno 111] Connection refused. Please suggest some ideas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM