Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTP

 
Tirthankar Dutta Chaudhuri
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can amy one help with java implementation of ftp . ( A java class that can ftp files .) i need the source code .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tirthankar,
Welcome to JavaRanch!

This JavaWorld article describes how to FTP in Java.
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;


this is good package for FTP (commons-net-1.3.0.jar,jakarta-oro.jar)

Thanks & regards
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The package Shiryans is talking about can be found here
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import org.apache.commons.net.ftp.FTPClient;
import java.net.*;
import java.io.*;
import java.lang.reflect.Array;

class newftp
{
public static void main(String[] args) throws java.net.MalformedURLException,java.net.UnknownHostException,java.io.IOException,java.io.FileNotFoundException
{
System.out.println("Hello World!");

FTPClient ftpClient = new FTPClient();
String host ="192.168.5.70";
String userid="ftptest";
String pwd="ftptest";
ftpClient.connect(host);
ftpClient.login(userid,pwd);
System.out.println("Ftp is connected ");


URL hp = new URL("ftp://192.168.5.70//folder1");

InputStream ip = hp.openStream();
System.out.println("Ftp is connected thro URL ");


// Make destination file
try
{
FileOutputStream dest = new java.io.FileOutputStream("F:\\folder1");

byte[] buf =(byte[])Array.newInstance(java.lang.Byte.TYPE,8192);
System.out.println(buf);

int byteCount;

while ( (byteCount = ip.read(buf)) > 0 )
{
dest.write(buf,0,byteCount);
}
dest.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used FTP from JScape, it was very simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic