• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to use jave to do remote ftp, download, upload stuff ?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to use jave to do remote ftp, download, upload stuff ? Korn shell script is very good at doing that ? How to do it in java ?

steve
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at Apache's Jakarta Commons Net
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this out ....
This is working for me ..

Srinivasa Raghavan

import java.net.*;
import java.io.*;
class ftpClient
{

URLConnection connection;
InputStream is;
OutputStream os;
String url;String user;
String password;

public ftpClient(String url,String user,String password)
{
this.url =url;
this.user= user;
this.password=password;
}

private void getConnection(String file)
{
try
{
StringBuffer location = new StringBuffer();
location.append("ftp://");
location.append(user + ":");
location.append(password + "@");
location.append(url + "/");
location.append(file +";type=i");
connection = (new URL(location.toString())).openConnection();
is = connection.getInputStream();
}
catch(Exception e)
{
System.out.println(e.toString() + "Here" );
}
}

public void download( String inputFile,String outputFile ) throws Exception
{
try
{
getConnection( inputFile );
int data;
InputStreamReader fileReader = new InputStreamReader(is);
FileOutputStream writer = new FileOutputStream( new File(outputFile) );

while ( (data = fileReader.read()) != -1 )
{
writer.write((char)data);
}
}
catch(Exception e)
{
System.out.println(e );
}
}

public static void main(String[] args)
{
String inputFile = "home/srinivas/test/reverse.java";
String outputFile = "C:\\reverse.java";
try
{
ftpClient client = new ftpClient("20.10.3.225","test","password");
client.download(inputFile,outputFile);
System.out.println( inputFile + " downloaded successfully to " + outputFile);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srini,

Do you have the upload() code? If you do, could you please post it?
I tried the upload with JDK1.3.1, it complains:
"java.net.UnknownServiceException: protocol doesn't support output
at java.net.URLConnection.getOutputStream(URLConnection.java:655)"

Seems like JDK1.3.1 doesn't support upload(put) file to ftp server. Is this true? Otherwise, did I get it wrong?
Please clarify. The download(get) works fine.

Thanks,
Annie
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this api, its free:

http://www.enterprisedt.com/products/edtftpj/overview.html

I am using this for my enterprise apps.
reply
    Bookmark Topic Watch Topic
  • New Topic