title: Upload file to remote folder from local folder using SFTP
body: <p>Am trying to upload file to remote folder from local folder.But am getting an error, I don't know where I made a mistake. I hope someone helps to find the solution. Thanks.</p>
  
  <p>The code given below:</p>
  
  <pre><code>public static void main(String[] args) {
          String server = "www.xyz.com";
          int port = 22;
          String user = "user";
          String pass = "admin@12";
  
          FTPClient ftpClient = new FTPClient();
          try {
  
              ftpClient.connect(server, port);
              System.out.println("1");
              ftpClient.login(user, pass);
              System.out.println("2");
              ftpClient.enterLocalPassiveMode();
  
              System.out.println("3");
  
              ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
              System.out.println("4");
  
              // APPROACH #1: uploads first file using an InputStream
              File firstLocalFile = new File("D:/UploadServlet.java");
  
              String firstRemoteFile = "Projects.zip";
              InputStream inputStream = new FileInputStream(firstLocalFile);
  
              System.out.println("Start uploading first file");
              boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
              inputStream.close();
              if (done) {
                  System.out.println("The first file is uploaded successfully.");
              }
  
  
  
          } catch (IOException ex) {
              System.out.println("Error: " + ex.getMessage());
              ex.printStackTrace();
          } finally {
              try {
                  if (ftpClient.isConnected()) {
                      ftpClient.logout();
                      ftpClient.disconnect();
                  }
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>Whenever I execute the code am getting the below error.</p>
  
  <pre><code>Error: Could not parse response code.
  Server Reply: SSH-2.0-OpenSSH_4.3
  org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
  Server Reply: SSH-2.0-OpenSSH_4.3
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:284)
      at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:335)
      at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:550)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:163)
      at FTPUploadFileDemo.main(FTPUploadFileDemo.java:26)
  org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
  Server Reply: Protocol mismatch.
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:284)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:460)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:520)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:569)
      at org.apache.commons.net.ftp.FTP.quit(FTP.java:781)
      at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:706)
      at FTPUploadFileDemo.main(FTPUploadFileDemo.java:58)
  </code></pre>