0
votes

I was trying to use ftp and I am getting the following error:

>>> ftp = ftplib.FTP('192.168.248.108')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/ftplib.py", line 118, in __init__
    self.connect(host)
  File "/usr/lib/python3.5/ftplib.py", line 153, in connect
    source_address=self.source_address)
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

I was trying to take it step by step since the whole client and server codes were not running. Help please. Thank you.

EDIT:
This is the client side code:

from ftplib import FTP

ftp = FTP('192.168.248.128')
ftp.login(user='username', passwd = 'password')
ftp.cwd('/Desktop/FTP')
def placeFile():

    filename = 'myfile.txt'
    ftp.storbinary('STOR '+filename, open(filename, 'rb'))
    ftp.quit()

placeFile()
1
Yes, what is the problem here?ashwin mahajan
You really need to show a minimal reproducible example so readers can have any idea what could be the problem you are facing.idjaw
can you connect to this address using another mean?Jean-François Fabre♦
@Jean-FrançoisFabre I tried using localhost and 127.0.0.1.ashwin mahajan
if you don't have a FTP server running on localhost, it will be the same problem.Jean-François Fabre♦

1 Answers

2
votes

First of all check this ip to see if ftp service is available, and if it is check the port that it is listening on, cause it maybe (rare but possible) is configured to listen on a different port than the standard one - 21 . Also maybe the connection is blocked by a firewall, and that is why connection gets refused.

Also haven't seen the whole code of yours but I think another/different problem is this: def placeFile() should be changed to this instead def placeFile(ftp) - cause the function placeFile doesn't really know that ftp references to the ftp client you created above.