This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to connect FTP server in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to connect FTP server in java " Watch "how to connect FTP server in java " New topic
Author

how to connect FTP server in java

prashant fusate
Greenhorn

Joined: Aug 24, 2005
Posts: 16
i am new person for java so anybody can send me a sample code for
how to connect Ftp server using javacode


psfusate
Ashish Vegaraju
Ranch Hand

Joined: Aug 19, 2004
Posts: 47
Hi,

Their are lots of APIs which you can use to connect to FTP server, and do the FTP operations like "get" "put" etc. Try to ask the same question to google.

some of the APIs are
1. EnterpriseDt's EDTFTPj API
2. Jakarta Commons - Net class library

Ashish
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

You can do basic FTP using the J2SE API:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
prashant fusate
Greenhorn

Joined: Aug 24, 2005
Posts: 16
Hi,
I have written a code for connecting to FTP server
It is properly connected with the referance server but during the copying file from remote server to local machine it giving me an nullpointer exception

could you please give me some suggesion that where i need to change the code or some alternet option.

import com.enterprisedt.net.ftp.*;
import java.net.*;
import java.io.*;
import java.net.InetAddress;
import java.text.*;
import java.util.*;


public class myFTPClient
{
String str[];
public static void main(String args[]) throws IOException, FTPException{

FTPClient f= new FTPClient("10.4.3.20");

f.login("ibolt","ibolt");

//FTPClient f = New FTPClient("10.1.1.4");
System.out.println("connection establish");

f.setConnectMode(FTPConnectMode.ACTIVE);
f.setType(FTPTransferType.ASCII);


//System.out.println("connection establish1");
f.get("C:/temp/pp.txt","map1.txt");

//System.out.println("connection establish3");

//System.out.println("connection released");


}



}




Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

It would be polite to mention where the null pointer exception is occurring. Maybe even give us the full exception stack trace.
[ September 28, 2005: Message edited by: Joe Ess ]
prashant fusate
Greenhorn

Joined: Aug 24, 2005
Posts: 16
Hi,
Thanks for the update.
This error occurs where you call the get method(i.e at the time serching the file in remote FTP Server)
And one more thing this error comes when we set connectType PASV for Active it is working fine.

it very difficult to understand me why this error comes for connection mode PASSIVE

java.lang.NullPointerException
at com.enterprisedt.net.ftp.FTPClient.initGet(FTPClient.java:1088)
at com.enterprisedt.net.ftp.FTPClient.getASCII(FTPClient.java:1110)
at com.enterprisedt.net.ftp.FTPClient.get(FTPClient.java:1021)
at myFTPClient.main(myFTPClient.java:22)
Exception in thread "main"
Ashish Vegaraju
Ranch Hand

Joined: Aug 19, 2004
Posts: 47
Hi

Check out this link :-- http://slacksite.com/other/ftp.html to get ur doubts cleared on Active and passive FTP.

Regards

Ashish
[ September 29, 2005: Message edited by: Ashish Vegaraju ]
prashant fusate
Greenhorn

Joined: Aug 24, 2005
Posts: 16
Dear Ashish Vegaraju
thank you very much

that document is enough for me to understands

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to connect FTP server in java
 
Similar Threads
FTP Connect
FTP server
get Firewall configuration in JAVA
connecting to linux using ftp
how to download files from a remote server via java code?