954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connect to ftp using java

Hi,
I need to connect to ftp and get the names of the files...
But am getting an UnknownHostException when i gave the ip..
Following is my code

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.io.FileUtils;
import java.io.IOException;

public class FtpTest {
  public static void main(String[] args) {

   try{
    FTPClient client = new FTPClient();

    client.connect("ftp.111.111.111.111");
    
    client.disconnect();

   }
   catch(Exception e){
	e.printStackTrace();
   }

  }
}

My IP is different than what i mentioned above..
Am getting the following error...

java.net.UnknownHostException: ftp.111.111.111.111
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
	at java.net.Socket.connect(Socket.java:525)
	at java.net.Socket.connect(Socket.java:475)
	at java.net.Socket.<init>(Socket.java:372)
	at java.net.Socket.<init>(Socket.java:186)
	at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:52)
	at org.apache.commons.net.SocketClient.connect(SocketClient.java:161)
	at org.apache.commons.net.SocketClient.connect(SocketClient.java:249)
	at FtpTest.main(FtpTest.java:12)


Pls Help :sad:

Thanks in Advance :)

vallikasturi
Newbie Poster
10 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Uhm, should that not be ftp://ipaddress?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

tried even dat...but dint worked...

Anyways thanq...
Finally i got dat...
its just the ip address... and not ftp. or ftp://
thank u

vallikasturi
Newbie Poster
10 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Yep, reading the documentation normally helps with stuff like that.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: