Now there are two processes A and B, A to Ftp upload A file, B monitoring A upload Ftp directory, timing, download files from this directory, now can only modify B of the code, not modify A
Code, could you tell me, how can B to ensure that the downloaded file is A complete file, rather than A file upload process? Now use the downloaded file is apache FTPClient,
Thank you very much!
CodePudding user response:
Cannot be guaranteed, the normal logic should be after the upload, A notice to B,
CodePudding user response:
Find file, regularly check the file first length, length unchanged after download
CodePudding user response:
reference tianfang reply: 3/f find file, regularly check the file first length, length unchanged after download Thank you for your reply, But if wait for a period of time, for some reason, (such as file upload in the waiting time temporarily stop), twice the size of the files, but there is no upload finished, how to do? CodePudding user response:
refer to the second floor of my great god reply: 666 to determine whether a file is released in full, look to whether can rename it: boolean flag=false; Try { Flag=ftpClient. Rename (name, name + ". TMP ");//rename If (flag) { //download name + ". TMP ", omit FtpClient. Rename (name + ". TMP ", name);//restore named } } the catch (IOException e) { e.printStackTrace(); return flag; Thank you for your answer, through testing, this method doesn't work, in the process of upload, ftpClient. Rename can perform, and returns true, FTP file name also changed, CodePudding user response:
I feel is always B there is no guarantee that the file integrity, if there is a network card dead and interrupt, B cannot judge; Should solve problems from A CodePudding user response:
Maoaq reference 4 floor response: Quote: refer to the third floor tianfang response: find file, regularly check the file first length, length unchanged after download Thank you for your reply, But if wait for a period of time, for some reason, (such as file upload in the waiting time temporarily stop), twice the size of the files, but there is no upload finished, how to do? After two same length, the number that is 5 times the same, for example, only considered the upload is complete, CodePudding user response:
refer to 6th floor dkwuxiang response: B is always I feel there is no guarantee that the file integrity, if there is a network card dead and interrupt, B cannot judge; Should solve the problem from A aspects Agree with you, We are doing a, upload a a.t mp, after the upload, a changed a.t mp to a.t xt CodePudding user response:
reference nature, 9/f, 80 response: Quote: refer to the sixth floor dkwuxiang response: B is always I feel there is no guarantee that the file integrity, if there is a network card dead and interrupt, B cannot judge; Should solve the problem from A aspects Agree with you, We are doing a, upload a a.t mp, after the upload, a changed a.t mp to a.t xt Yes, normal process is as follows