aspose file tools
The moose likes Java in General and the fly likes execute ftp commands using java API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

execute ftp commands using java API

twity Panu
Greenhorn

Joined: Jan 31, 2007
Posts: 7
URL url = new URL("ftp://admin:administrator@10.20.30.9");
URLConnection urlc = url.openConnection();
InputStreamReader isr = new InputStreamReader(urlc.getInputStream());
Process process = Runtime.getRuntime().exec(urlc + "cd SABB_APP dir");
BufferedReader input = new BufferedReader(isr);
String s;
while ((s = input.readLine()) != null)
{
System.out.println(s);
}input.close();
I have done this thing for connection,but i want to execute mput and mget commands from java..I thought to use Runtime.getRuntime.exec()
but was not able to do.....
plaese help me out.....
i have an urgency......
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
Welcome to JavaRanch.

While there's probably a way to make this work, be aware that Runtime.exec has several pitfalls (as explained here) that make it harder to work with interactive programs than it would at first appear.

I think you'd be much better off using an ftp client library like Jakarta Commons Net. It doesn't support mget and mput directly, though, so you'd have to code a simple loop.
[ January 31, 2007: Message edited by: Ulf Dittmer ]
twity Panu
Greenhorn

Joined: Jan 31, 2007
Posts: 7
please help,i want some perfect solution..................
I mainly want to upload a file from my local machine to server..
using ftp mput.
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
Please don't post the same question to multiple forums. You now have answers here and in this duplicate thread. CarefullyChooseOneForum
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: execute ftp commands using java API