title: FTP server not sending data to proxy in Python with sockets
body: <p>I'm building a proxy in Python between a ftp client and a ftp server. All the control phase and data phase is well done (currently on active mode), but when I send the request (LIST, for example), server does not send the information back. I don't know what is causing this fault... </p>
  
  <p>Here is the Wireshark capture:</p>
  
  <p><img src="https://i.stack.imgur.com/n84me.png" alt="Wireshark capture"></p>
  
  <p>And the corresponding code:</p>
  
  <pre><code>print(f"Waiting for a message from the server to the PORT message")
  answer = fw_proxy_server.recv(BUFFER_FTP)
  print(answer) # 200 PORT command successful
  fw_proxy_client.send(answer) # forward to client
  
  # Create the socket to listen on 192.168.30.80:port (IP_PROXY:port)
  server_socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  server_socket2.setsockopt(socket.SOL_SOCKET, 25, str(INTERFACE_PROXY_SERVER + '\0').encode('utf-8'))
  server_socket2.bind((IP_PROXY, port))
  server_socket2.listen()
  
  print(f"Waiting for a message from the client")
  message = fw_proxy_client.recv(BUFFER_FTP) # REQUEST: LIST
  
  print(f"Forwarding message from the server")
  message = send(fw_proxy_server, "LIST") # REQUEST: LIST (sent to port 21)
  
  # Accept an incoming connection from the Server with data
  
  server_socket2, data_address = server_socket2.accept() # HERE PROGRAM HANG
  print(f"Data connection from {data_address} has been established!")
  
  print(f"Waiting for a message from the data from server")
  message = fw_proxy_server.recv(BUFFER_FTP) # never executed
  </code></pre>
  
  <p>The IPs are the following:<br/>
  Client: 192.168.40.50<br/>
  Proxy-client: 192.168.40.80<br/>
  Proxy-server: 192.168.30.80<br/>
  Server: 192.168.30.90</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>Changed order of listening to port, so that the port is listened before sending the PORT command and the LIST request. Same result, connection refused:</p>
  
  <pre><code>start = str(message).find("(")
  end = str(message).find(")")
  tuple = str(message)[start+1:end].split(',')
  port = int(tuple[4])*256 + int(list(filter(str.isdigit, tuple[5]))[0])
  #Create the socket to listen on 192.168.40.80:port
  server_socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  server_socket2.setsockopt(socket.SOL_SOCKET, 25, str(INTERFACE_PROXY_SERVER + '\0').encode('utf-8'))
  server_socket2.bind(("192.168.40.80", port)) # With 192.168.30.80 it doesn't work too
  server_socket2.listen()
  
  answer = send(fw_proxy_server, "PORT 192,168,30,80," + tuple[4] + "," + tuple[5])
  print(f"Waiting for a message from the server to the PORT message")
  print(answer) # 200 PORT command successful
  fw_proxy_client.send(answer)
  
  #Create the socket to forward the data to the server
  
  print(f"Waiting for a request from the client") # REQUEST: LIST
  message = fw_proxy_client.recv(BUFFER_FTP)
  print(message)
  
  fw_proxy_server.send(message)
  print(f"Waiting for an answer from the server") # Response 425: Unable to build data connection: Connection refused
  answer = fw_proxy_server.recv(BUFFER_FTP)
  print(answer)
  
  
  #Accept an incoming connection from the Client
  server_socket2, data_address = server_socket2.accept() #Program hang
  print(f"Data connection from {data_address} has been established!")
  
  print(f"Waiting for a message from the server")
  print(answer)
  </code></pre>