• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I want to download file from FTP using java program

 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks,

I have come across one problem.I have a JAVA program which downloads file from the FTP.This is working fine.
Now my requirment is like, if i send request to download file from FTP.
Request is like ,consdier file name "myfile" then is there anyway by which i can download all the files which starts "myfile" on the FTP.
file name could be like : myfile , myfile_x,Myfile_y,........
then the request should get all the file (from FTP) starts with myfile.

suggest me any api or anyway.
______________________________________________________
Mintoo
______________________________________________________
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FTP protocol itself can do this (the command is generally "mget" instead of "get"). Whether you can use that in your client depends on whether the FTP library you're using supports this.

It should always be to possible to list the contents of an FTP directory, and then to retrieve all files that match a particular pattern. You'd just have to do the matching in your code instead of having the library do it for you.
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

I am using the edt.ftp libarary.which does not have method name like "mget" ,it has all the method which starts with "get" .

I too was thinking for the second option , to get list of file and make pattern using regex then find out.

__________________________________
Mintoo
__________________________________
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to get list of file and make pattern using regex then find out
FTP servers don't give you a consistent directory listing format. The results differ depending on the ftp server you use. If you make your regular expression configurable, this will help you making the code usable with different servers.

Regards, Jan
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FTP servers don't give you a consistent directory listing format.
I would be very surprised if the FTP library in question (edt.ftp) doesn't abstract away those differences, just like other FTP client libraries (like Apache Commons Net) do.
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah , correct I have made my regex pattern configrable and dynamic.So that it will not break.
Because afte taking so much pain to discove the method ,which give me the all the file listing in a directory,finally i encountered with the method.

Hence ball is in my court so i will play with regex and the list(contains the name of the files).

I too have earlier used apache library where i could not remember exactly but there were some method like mget ,etc....But the problem is i have used this library and most of the other modules is using this library .Hence i can not push myself to change the library.


_______________________
Mintoo
SCJP 1.4
_______________________
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic