title: FTPClient Connection refused
body: <p>I am trying to copy file through FTPClient and testing in my local system</p>
  
  <p>My code is like this with my IPv4 address as input for host</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  
  import org.apache.commons.net.PrintCommandListener;
  import org.apache.commons.net.ftp.FTP;
  import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPReply;
  
  public class FTPUploader {
  
  FTPClient ftp = null;
  
  public FTPUploader(String host, String user, String pwd) throws Exception{
      ftp = new FTPClient();
      ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
      int reply;
      ftp.connect(host);
      reply = ftp.getReplyCode();
      if (!FTPReply.isPositiveCompletion(reply)) {
          ftp.disconnect();
          throw new Exception("Exception in connecting to FTP Server");
      }
      ftp.login(user, pwd);
      ftp.setFileType(FTP.BINARY_FILE_TYPE);
      ftp.enterLocalPassiveMode();
  }
  public void uploadFile(String localFileFullName, String fileName, String hostDir)
          throws Exception {
      try(InputStream input = new FileInputStream(new File(localFileFullName))){
      this.ftp.storeFile(hostDir + fileName, input);
      }
  }
  
  public void disconnect(){
      if (this.ftp.isConnected()) {
          try {
              this.ftp.logout();
              this.ftp.disconnect();
          } catch (IOException f) {
               // DO NOTHING
          }
      }
  }
  public static void main(String[] args) {
     try{
         System.out.println("Start");
         FTPUploader ftpUploader = new FTPUploader("10.66.***.***", "username", "password");
  
                    ftpUploader.uploadFile("D:/Venkatesh.pptx", "65.pptx", "C:/Users/VENKATESH/Desktop");
         ftpUploader.disconnect();
         System.out.println("Done");
     }catch(Exception exception){
         exception.printStackTrace();
     }
  }
  
  }
  </code></pre>
  
  <p>Now by this, Iam getting the following Exception</p>
  
  <pre><code>Start
  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:168)
  at org.apache.commons.net.SocketClient.connect(SocketClient.java:189)
  at org.apache.commons.net.SocketClient.connect(SocketClient.java:278)
        at fileTransfer.FTPUploader.&lt;init&gt;(FTPUploader.java:21)
  at fileTransfer.FTPUploader.main(FTPUploader.java:51)
  </code></pre>
  
  <p>What is the mistake iam doing ????</p>