• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

FTP using exec(String command) of Runtime

 
author
Posts: 469
20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have been trying to make a FTP client using exec(...) method of java.lang.Runtime. I coded the client like this:
Process p = (Runtime.getRuntime()).exec("ftp www.somesitename.com");
After this I obtain the InputStream and OutputSream associated with the process. Now the problem arise:
(1). When I wrap the InputStream into BufferedReader then a call to readLine() method of BufferedReader results in no output
(2). How one can pass the user name and password to this ftp connection using the output stream of the process
Can someone help me find out a simple solution to creating FTP client using just the exec(...) method rather than using Sockets and ServerSockets.
regards
ashish sarin
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Look at the 13.5 JProgressBar in FTP client application example in the magnificient book Swing 2nd ed. by Robinson and Vorobiev.
But consider also what Sun says about Using sun.* packages
[ April 23, 2004: Message edited by: Jose Botella ]
[ April 23, 2004: Message edited by: Jose Botella ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to spawn a new thread to read from the OutputStream because its going to block on calls to read. That way you can still get your interactive input into the new process' InputStream.
I think using URL and URLConnection is easier:

or something like that.
[ April 23, 2004: Message edited by: Joe Ess ]
 
Ashish Sarin
author
Posts: 469
20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just wondering how to take care of 'ls' command. Will i be able to obtain the directory listing properly if I use exec(...) command ??
regards
ashish sarin
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if you're reading the stdout stream. Here's a runtime exec exercise I did. It's not 100% bug free: http://www.surfscranton.com/architecture/CmdServer.htm The server portion has the runtime exec stuff.
Have you looked around for FTP APIs for Java? I've seen some open source or free packages mentioned but never tried any. That would give you the best possible control over FTP. This runtime exec stuff will get complicated in a hurry - reading stdout and errout on threads, synchronizing to examine results, etc.
 
reply
    Bookmark Topic Watch Topic
  • New Topic