title: How to connect to an FTP server with sockets?
body: <p>I am trying to create a simple FTP client but somehow the FTP connection can not be established.</p>
  
  <p>I used the following code:</p>
  
  <pre><code>import socket 
  sock = socket.socket() 
  sock.connect(('localhost', 21)) 
  data = 'USER adm\r\n'.encode() 
  sock.send(data) 
  print('Close') 
  sock.close() 
  </code></pre>
  
  <p>The logs of the FTP server I try to connect to look like this:</p>
  
  <blockquote>
    <p>(048507)01.05.2018 06:00:03 - (not logged in) (127.0.0.1)>
    Connected on port 21, sending welcome message...<br>
    (048507)01.05.2018 06:00:03 - (not logged in) (127.0.0.1)>
    220-FileZilla Server 0.9.60 beta<br>
        (048507)01.05.2018 06:00:03 - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)<br>
        (048507)01.05.2018 06:00:03 - (not logged in) (127.0.0.1)> 220 Please visit <a href="https://filezilla-project.org/" rel="nofollow noreferrer">https://filezilla-project.org/</a><br>
        (048507)01.05.2018 06:00:03 - (not logged in) (127.0.0.1)> disconnected.</p>
  </blockquote>
  
  <p>I tried to send the <code>USER adm</code> command but can not find it in the logs. How can I establish a successful connection to a FTP server with sockets?</p>