• Post Reply Bookmark Topic Watch Topic
  • New Topic

Download file through FTP

 
Petter Bengtsson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!