Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to connect FTP server in java

 
prashant fusate
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new person for java so anybody can send me a sample code for
how to connect Ftp server using javacode
 
Ashish Vegaraju
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do basic FTP using the J2SE API:
 
prashant fusate
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ashish Vegaraju
thank you very much

that document is enough for me to understands

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic