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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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 ]

Ping & DNS - updated with new look and Ping home screen widget
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
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Please don't post the same question to multiple forums. You now have answers here and in this duplicate thread. CarefullyChooseOneForum
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execute ftp commands using java API
 
Similar Threads
FTP using exec(String command) of Runtime
how to execute ftp commands from java
Firing statements into Command prompt.
Execute "echo $BASHPID" in Linux using Java
Redirect output from stderr, stdout to a JTextArea