0

Hello Everybody,

          I am having a doubt regarding how to upload a file to multiple machines or servers.
          I tried using with FTP but getting ConnectException:connection Refused



import sun.net.ftp.*;
import java.io.*;

public class SendFile {
 public static void main(String args[]) {
   String hostname = "172.14.3.23"; //Remote FTP server: Change this
   String username = "usernamee"; //Remote user name: Change this
   String password = "password"; //Remote user password: Change this
   String upfile = "test.txt"; //File to upload passed on command line
   String remdir = "/home/user"; //Remote directory for file upload
   FtpClient ftp = new FtpClient();
   try {
      ftp.openServer(hostname); //Connect to FTP server
      System.out.println("Connected..");
      ftp.login(username, password); //Login
      ftp.binary(); //Set to binary mode transfer
      ftp.cd(remdir); //Change to remote directory
      File file = new File(upfile);
      OutputStream out = ftp.put(file.getName()); //Start upload
      InputStream in = new FileInputStream(file);
      byte c[] = new byte[4096];
      int read = 0;
      while ((read = in.read(c)) != -1 ) {
         out.write(c, 0, read);
      } //Upload finished
      in.close();
      out.close();
      ftp.closeServer(); //Close connection
   } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
   }
 }
}

Replies will be appriciated..

Thank in advance

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

Have you tried another FTP program to the same site to see that you have the correct values?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.