| Author |
FTP Client
|
Mutua Kakinyi
Greenhorn
Joined: Apr 21, 2011
Posts: 7
|
|
I am trying to make a connection to FTP server through java code
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPClass {
public static void main(String[] args) throws IOException {
FTPClient ftp = new FTPClient();
ftp.connect("ftp://41.215.1.22/store");
ftp.login("", "");
int reply = ftp.getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
System.out.println("Connected Success");
} else {
System.out.println("Connection Failed");
ftp.disconnect();
}
}
but i keep getting the error below: Exception in thread "main" java.net.UnknownHostException: ftp://41.215.1.22/store/
Is it to do with the use of IP instead of a server name? What is way out if I still want to use the IP address?
Please someone help me.
Mutua
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5844
|
|
|
Perhaps you should read the docs for the connect() method closely. If you look closely at the error message (and read its docs), I think you'll find that it thinks you're trying to connect to a host whose name or IP address is "ftp://41.215.1.22/store/". So most likely you are only supposed to give connect() the host, not the entire URL.
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Mutua Kakinyi wrote:I am trying to make a connection to FTP server through java code
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPClass {
public static void main(String[] args) throws IOException {
FTPClient ftp = new FTPClient();
ftp.connect("ftp://41.215.1.22/store");
ftp.login("", "");
int reply = ftp.getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
System.out.println("Connected Success");
} else {
System.out.println("Connection Failed");
ftp.disconnect();
}
}
but i keep getting the error below: Exception in thread "main" java.net.UnknownHostException: ftp://41.215.1.22/store/
Is it to do with the use of IP instead of a server name? What is way out if I still want to use the IP address?
Please someone help me.
Mutua
do not use commons.net use ftp4j instead because while uploading a file using commons.net the file gets corrupted , i have this problem while i was developing the ftp client so
if you dont change the library now surely you will get a hell lot of pain in your neck.
|
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5844
|
|
naved momin wrote:
do not use commons.net use ftp4j instead because while uploading a file using commons.net the file gets corrupted , i have this problem while i was developing the ftp client so
Don't take this personally, but my guess is that the problems were caused by user error.
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Don't take this personally,
no i will not
my guess is that the problems were caused by user error.
but some one here itself told me that commons.net has a problem in uploading and the after changing just a library the same code runs without this uploading problem
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5844
|
|
naved momin wrote:
Don't take this personally,
no i will not
my guess is that the problems were caused by user error.
but some one here itself told me that commons.net has a problem in uploading and the after changing just a library the same code runs without this uploading problem
Okay, fair enough.
@Mutua: You should of course investigate for yourself and draw your own conclusions, but just keep in mind if you have problems with data corruption, that is has been mentioned that this library may have that problem.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
naved momin wrote:but some one here itself told me that commons.net has a problem in uploading and the after changing just a library the same code runs without this uploading problem
This is the sort of rubbish which people, unfortunately, actually base their decisions on. Please don't post rumours like this without providing information to support them.
My company has been using Commons.net code to do FTP transfers for several years now. So my belief is that those "problems in uploading" are, as already suggested, based on errors made by programmers using the product incorrectly.
|
 |
 |
|
|
subject: FTP Client
|
|
|