Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Different file size my: local machine vs. server  RSS feed

 
Jan Kwiatkowski
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dear Programmers,

Maybe someone could help me with this. I've searched Sockets and Internet Protocols, but I guess no one had the same problem.
Ok, here's my problem.
My appication needs to upload a file by ftp(using Jakarta-commons-net-2.8) on the server, but before it starts it needs to check if the file is on the server already. What is the best criteria to say that two files are eqaul? I mean I would like to check the size and the name, but when it comes to the size, there's a problem, because the the object of type File lets's say file(on my local machine Windows XP), when it is send to the server(Linux) and retrieved with the following snippet of Code:


it has different size!
this prints:
, even though the files are eqaul, couse I upload the same file.
Could it be possible? I know that File(SE 6) and FTPFile(from Jakarta), are not the same types, and the methods used to retrieve the size of the file are different.

Could someone explain this to me please? What's the best way to check(using ftp) to say two files are eqaul (only by the name)?

cheers,
j.k








>
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't determine if files are different or the same based on file names. Comparing file names and sizes isn't reliable either. For example, if I wanted to save this post as a file, I could have an identically named file with the same size but completely different contents. And of course have different named files but are otherwise identical.


Most FTP clients give you the option to overwrite an existing file if the uploaded file is newer, but timestamps can be misleading as well. If a file to be uploaded is equal in every relevent respect to one already on the server, overwriting isn't a bad thing, unless it is a large file.

If you really need to know if they are equal, download the file in question, hash with a fairly strong message digest(say SHA 256 or 512) and compare. If the hashes match, you can be reasonably sure they are the same. However, if they don't match, you won't know if they are related in anyway, if that is important to you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!