title: Errors when trying to upload file to FTP server with ftplib in Python
body: <p>I'm trying to upload a file to a test FTP server in <a href="https://dlptest.com/ftp-test/" rel="nofollow noreferrer">https://dlptest.com/ftp-test/</a>. I'm working with Python and ftplib in the ipython console, but when I call FTP.storlines('STORE file1.txt', open('file1.txt')) it gives me the following error:</p>
  
  <pre><code>In [1]: import ftplib, os
  
  In [2]: ftp = ftplib.FTP('ftp.dlptest.com')
  
  In [3]: ftp.login('dlpuser@dlptest.com', 'e73jzTRTNqCN9PYAAjjn')
  Out[3]: '230 OK. Current restricted directory is /'
  
  In [4]: ftp.storlines('STOR file1.txt', open('file1.txt'))
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-4-df84f4fce912&gt; in &lt;module&gt;()
  ----&gt; 1 ftp.storlines('STOR file1.txt', open('file1.txt'))
  
  /usr/lib/python3.7/ftplib.py in storlines(self, cmd, fp, callback)
      536                     break
      537                 if buf[-2:] != B_CRLF:
  --&gt; 538                     if buf[-1] in B_CRLF: buf = buf[:-1]
      539                     buf = buf + B_CRLF
      540                 conn.sendall(buf)
  
  TypeError: a bytes-like object is required, not 'str'
  
  In [5]: 
  </code></pre>
  
  <p>And when I do <code>ftp.storlines('STOR file1.txt', open('file1.txt', 'rb')</code>:</p>
  
  <pre><code>In [5]: ftp.storlines('STOR file1.txt', open('file1.txt', 'rb'))
  ---------------------------------------------------------------------------
  error_reply                               Traceback (most recent call last)
  &lt;ipython-input-5-afee52811a1f&gt; in &lt;module&gt;()
  ----&gt; 1 ftp.storlines('STOR file1.txt', open('file1.txt', 'rb'))
  
  /usr/lib/python3.7/ftplib.py in storlines(self, cmd, fp, callback)
      528         """
      529         self.voidcmd('TYPE A')
  --&gt; 530         with self.transfercmd(cmd) as conn:
      531             while 1:
      532                 buf = fp.readline(self.maxline + 1)
  
  /usr/lib/python3.7/ftplib.py in transfercmd(self, cmd, rest)
      397     def transfercmd(self, cmd, rest=None):
      398         """Like ntransfercmd() but returns only the socket."""
  --&gt; 399         return self.ntransfercmd(cmd, rest)[0]
      400 
      401     def login(self, user = '', passwd = '', acct = ''):
  
  /usr/lib/python3.7/ftplib.py in ntransfercmd(self, cmd, rest)
      357         size = None
      358         if self.passiveserver:
  --&gt; 359             host, port = self.makepasv()
      360             conn = socket.create_connection((host, port), self.timeout,
      361                                             source_address=self.source_address)
  
  /usr/lib/python3.7/ftplib.py in makepasv(self)
      335     def makepasv(self):
      336         if self.af == socket.AF_INET:
  --&gt; 337             host, port = parse227(self.sendcmd('PASV'))
      338         else:
      339             host, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername())
  
  /usr/lib/python3.7/ftplib.py in parse227(resp)
      843 
      844     if resp[:3] != '227':
  --&gt; 845         raise error_reply(resp)
      846     global _227_re
      847     if _227_re is None:
  
  error_reply: 200 TYPE is now ASCII
  </code></pre>
  
  <p>Can you help me find out why is this happening? Thank you in advance!</p>