File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Problem with FTPClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Problem with FTPClient" Watch "Problem with FTPClient" New topic
Author

Problem with FTPClient

James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
Hi All,


In my FTP Server all files are coming from third party devices. Now, for fetching these files from ftp server I am using
commons-net-1.4.1.jar API. It's working fine completely.

But what problem I have is like when third-party system writes file on my ftp server, though write operation is going on my program pick up that file. So, as the final result I am getting incomplete files.
So, what can I do in this case???

Thanks!!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41112
    
  45
If you can't synchronize read and write file accesses (meaning you can make sure that they don't overlap), you could make a copy of any file you're about to download, and then download the copy instead of the original (which might be overwritten during the download).


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Too difficult a question for us beginners. Moving.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi James,

As an alternative solution: The JCA FTP connector we wrote had the ability to detect the age of a file (look at the last modified date). If the date wasn't more than a couple of mionutes it would hold off from picking up that file.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
Martijn Verburg wrote:Hi James,

As an alternative solution: The JCA FTP connector we wrote had the ability to detect the age of a file (look at the last modified date). If the date wasn't more than a couple of mionutes it would hold off from picking up that file.


Hi Martijn,

Thanks for your reply. I am using (org.apache.commons.net.ftp.FTPClient)'s listFiles() method for getting files. Now, here it gives me perfect things of files. Even in this API I can also make changes like your solution of last modified date. But the thing I think it's not good solution for programmers. So, is there anything that I can check that if file is in write mode so I can check lock on file or something like that......

Because take a case like if file is bigger and third-party system is taking 5 mins. to write that file then also it will create problem.

I hope all of you get what I am trying to say!!!

Thanks again for your reply!!!

and again waiting for your valuable reply!!!

Thanks,
James
Raj S Kumar
Ranch Hand

Joined: Aug 06, 2006
Posts: 48
As an alternative, before downloading a file, you could wait for 10 secs and compare the file size before and after waiting.


Raj S Kumar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Rajkumar, please read your private messages.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

James Basller wrote:
Thanks for your reply. I am using (org.apache.commons.net.ftp.FTPClient)'s listFiles() method for getting files. Now, here it gives me perfect things of files. Even in this API I can also make changes like your solution of last modified date. But the thing I think it's not good solution for programmers. So, is there anything that I can check that if file is in write mode so I can check lock on file or something like that......


As a file is written the last modified date is typically updated. If you are concerned that this is not occurring then you can periodically check the file size (as another poster above has suggested).
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi James ,

I dont have much idea abt the FTP stuff.

If you can get the file instance from FTP , Please refer the below link which says how to aquire the lock for files
do can do vise versa i think .

locking file


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with FTPClient
 
Similar Threads
downloading all the files in a folder through ftp
FTP Put a zip file that contains text files in Linux
apache commons FTPClient issue
Java FTP File Transfer
uploading files in JSP