Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes I want to download file from FTP using java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "I want to download file from FTP using java program" Watch "I want to download file from FTP using java program" New topic
Author

I want to download file from FTP using java program

Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
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
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
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.


Ping & DNS - my free Android networking tools app
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
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

Joined: Dec 20, 2006
Posts: 2504
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
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

Joined: Aug 21, 2007
Posts: 61
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
_______________________
 
 
subject: I want to download file from FTP using java program