File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTP Client

 
Mutua Kakinyi
Greenhorn
Posts: 7
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20161
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic