title: apache commons net ftp sendCommand returns wrong reply code
body: <p>I have an FTP server, I am trying to upload a file</p>
  
  <p>in FTPClient.<em>openDataConnection</em>(), I get down to the line</p>
  
  <pre><code>if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
      return null;
  }
  </code></pre>
  
  <p>The command is "STOR" and arg is "edf0864d-1651-43b2-8453-d160bf9d0742" (the name of the file I want to store)</p>
  
  <p>The server log looks like:</p>
  
  <pre><code>PORT 86,185,26,230,213,101
  200 Port command successful
  STOR edf0864d-1651-43b2-8453-d160bf9d0742
  150 Opening data channel for file upload to server of "/edf0864d-1651-43b2-8453-d160bf9d0742"
  (Up to here after calling sendCommand)
  PORT 86,185,26,230,213,102
  200 Port command successful
  </code></pre>
  
  <p>From the logs the response code is 150, but sendCommand returns a response code of 200</p>
  
  <p>Other potentially important information</p>
  
  <p>I'm using filezilla server</p>
  
  <p>The server works most of the time, with the exact same code. The initial upload of the file works fine, then when I choose another file to overwrite the first upload, this happens.</p>
  
  <p>Following on from that, there's another file with the same name, but I haven't had trouble with that before.</p>
  
  <p>The server is configured for passive connections as far as I can tell, it doesn't shout at me when I start it up like it used to, but the PASV command produces a 421 could not create socket error. I'm using ACTIVE_LOCAL mode</p>
  
  <p>I'm using apache commons net 3.6</p>
  
  <p>Let me know if there's any more information that can help</p>
  
  <p>This is the relevant parts of the java:</p>
  
  <pre><code>FTPClient ftp = new FTPClient();
  String server = &lt;server ip&gt;;
  int port = 21;
  String username = &lt;username&gt;;
  String password = &lt;password&gt;;
  try{
      ftp.connect(server, port);
  }
  catch(SocketException e){
      throw new FTPCouldNotConnectException("Threw SocketException during connection", e);
  }
  catch(IOException e){
      throw new FTPCouldNotConnectException("Threw IOException during connection", e);
  }
  int reply = ftp.getReplyCode();
  if(!FTPReply.isPositiveCompletion(reply)){
      try{
          ftp.disconnect();
          throw new FTPCouldNotConnectException("Reply Code: " + reply + ", Could not connect");
      }
      catch(IOException e){
          throw new FTPCouldNotConnectException(
                  "Threw IOException during disconnection after failing to connect with reply code: " + reply,
                  e);
      }
  }
  else{
      try{
          if(ftp.login(username, password)){
              LOGGER.info("Successfully logged in to ftp server");
              ftp.setFileTransferMode(org.apache.commons.net.ftp.FTP.STREAM_TRANSFER_MODE);
              ftp.setFileStructure(org.apache.commons.net.ftp.FTP.FILE_STRUCTURE);
              ftp.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
              ftp.enterLocalActiveMode();
          }
          else{
              LOGGER.warn("Failed to log in to ftp server");
          }
      }
      catch(IOException e){
          throw new FTPCouldNotConnectException("Failed to log in to server, threw ioexception", e);
      }
  }
  try{
      ftp.storeFile("edf0864d-1651-43b2-8453-d160bf9d0742", new FileInputStream("test.jpg"));
  }
  catch(IOException e){
      LOGGER.error("java.io.IOException caught", e);
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FZQ3w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FZQ3w.png" alt="Wireshark Packets (let me know if you need more)"></a></p>