• 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:

Download file through FTP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem: I need to login to a FTP-server and download a specific file. Does anyone have a smart and simple solution to this?
Thanks
/Petter
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Offhand, I would probably use the FTP class in Jakarta Commons/Net. Alternately you can use the Runtime 's exec() method to send ftp commands through your OS. Probably the best way to do that is to create a script (.bat or shell script or whatever works for your OS) in a file, and use exec() to execute the file contents. Using a file makes it easier to debug the script without having to go through the Process interface, which can be painful. Note that any exec() solution will not be cross-platofrom, so prefer Jakarta Commons/Net unless there's some problem with that.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am actually doing the exact opposite thing (uploading) . if you go to www.jscape.com and get there inetfactory.zip it is a great resource on how to upload/download.
now on to some simple code......
import com.jscape.inet.ftp.*;

public class MyFtpAdapter extends FtpAdapter
{

public void disconnected(FtpDisconnectedEvent evt){}
public static void main (String[] args){
try{
Ftp ftp = new Ftp("ftp.site.com","user","password");
ftp.connect();
ftp.download("stuff.txt");
ftp.disconnect();
}
catch(Exception e){
e.printStackTrace();
}
}
}
this helped me out and had me ftping in no time, hope it helps you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic