ConnectionRefusedError: [Errno 111] Connection refused
<p>I was trying to use <code>ftp</code> and I am getting the following error:</p>

<pre><code>&gt;&gt;&gt; ftp = ftplib.FTP('192.168.248.108')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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
</code></pre>

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

<p><strong>EDIT:</strong><br>
This is the client side code:</p>

<pre><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()
</code></pre>

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

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

python ftp