This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with FTPClient

 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49442
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for us beginners. Moving.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an alternative, before downloading a file, you could wait for 10 secs and compare the file size before and after waiting.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajkumar, please read your private messages.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic