This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes FTP Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "FTP Client" Watch "FTP Client" New topic
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: 6109
    
    6

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: 688

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: 6109
    
    6

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: 688



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: 6109
    
    6

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: 18541
    
    8

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.
 
wood burning stoves
 
subject: FTP Client
 
Similar Threads
FTP between SUN and Linux servers
Problem FTP the files using java
how to connect FTP server in java
Need Expert help with FTP
Connect to FTP site with Apache commons net FTP client through Proxy