title: Connect to Localhost with Java FTP
body: <p>I'm developing FTP program on JAVA. I'm using Apache Commons Net Library. My Codes are below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import java.io.IOException;
  import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPReply;
  public class ServerClass {
      private static void showServerReply(FTPClient ftpClient) {
          String[] replies = ftpClient.getReplyStrings();
          if (replies != null &amp;&amp; replies.length &gt; 0) {
              for (String aReply : replies) {
                  System.out.println("SERVER: " + aReply);
              }
          }
      }
      public static void main(String[] args) {
          String server = "127.0.0.1";
          int port = 80;
          String user = "root";
          String pass = "root";
          FTPClient ftpClient = new FTPClient();
          try {
              ftpClient.connect(server, port);
              showServerReply(ftpClient);
              int replyCode = ftpClient.getReplyCode();
              if (!FTPReply.isPositiveCompletion(replyCode)) {
                  System.out.println("Operation failed. Server reply code: " + replyCode);
                  return;
              }
              boolean success = ftpClient.login(user, pass);
              showServerReply(ftpClient);
              if (!success) {
                  System.out.println("Could not login to the server");
                  return;
              } else {
                  System.out.println("LOGGED IN SERVER");
              }
          } catch (IOException ex) {
              System.out.println("Oops! Something wrong happened");
              ex.printStackTrace();
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>But I can't connect my localhost. I want to login my localhost and see my file. 
  My errors are below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Oops! Something wrong happened
  java.net.ConnectException: Connection refused: connect
   at java.net.DualStackPlainSocketImpl.connect0(Native Method)
   at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
   at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
   at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
   at java.net.PlainSocketImpl.connect(Unknown Source)
   at java.net.SocksSocketImpl.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
   at org.apache.commons.net.SocketClient.connect(SocketClient.java:209)
   at com.emrecanoztas.ftp.ServerClass.main(ServerClass.java:22)</code></pre>
  </div>
  </div>
  </p>
  
  <p>can you help me anybody? Thanks!..</p>