
Hi, I need to connect to the ftp and get the files through a java program.. I wrote the following 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();
}
}
}
I have given a different ip than the above... But its not connecting... It shows me a runtime exception of UnknownHostException..
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)
the same worked me well when i entered in the browser... whats the problem here... Pls Help
Thanks in advance..

try like client.connect("111.111.111.111"); Because all ready we are getting FTPClient so don't need to try with ftp://
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.