|
-
Jul 20th, 2009, 04:25 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Compare textfile from server with local and download
Hi,
I'm willing to compare a textfile (whatever) which contains a few lines of text. After the comparission it should download and replace the "changed" folder/file.
e.g.
(Local txtFile)
maps: 1.0.0
db1: 1.0.0
db2. 1.0.0
(Server txtFile)
maps: 1.0.1
db1: 1.0.0
db2. 1.0.0
Does anyone have a good example or could help me out? Please state that this is just an option, perhaps there is a better way to do this.
-
Jul 20th, 2009, 05:47 AM
#2
Re: Compare textfile from server with local and download
Compare how? If you mean the contents then you can't compare before downloading. If you haven't downloaded the file then how can you compare it to something?
If it's your intention to determine whether a file has changed or not then you should use a checksum value, which is a single value that represents the entire contents. If two files are different then they will produce different checksums so it's a good way to know if a file has changed without downloading lots of data. The checksum will need to be provided on the server for you to access, so you must have control over that. If you don't then you're out of luck. In that case you'll just have to download the whole thing and then create a checksum to compare to your existing file.
As far creating the checksum, a common method is to create an MD5 hash. A search will find examples on the forum, MSDN and the web.
-
Jul 20th, 2009, 05:52 AM
#3
Thread Starter
PowerPoster
Re: Compare textfile from server with local and download
Compare how? If you mean the contents then you can't compare before downloading
So it isn't possible to read the file remote?
If it's your intention to determine whether a file has changed
No. As you can see I'm checking the numbers only.
-
Jul 20th, 2009, 07:06 AM
#4
Re: Compare textfile from server with local and download
 Originally Posted by Radjesh Klauke
So it isn't possible to read the file remote?
What would that mean? If you're going to compare the contents of the remote file with the contents of a local file then you've got to have the contents of the remote file locally. You can't compare two things if you haven't got the two things together. That means that you have to transfer the contents of one of the files to the other location. You're not going upload the contents of the local file to the server are you? The only other option is downloading the contents of the remote file to your machine.
 Originally Posted by Radjesh Klauke
No. As you can see I'm checking the numbers only.
But doesn't it follow that if the version numbers are the same then the file is the same and if the file has changed then the version numbers have changed?
-
Jul 20th, 2009, 09:45 AM
#5
Thread Starter
PowerPoster
Re: Compare textfile from server with local and download
Why is it so hard to just give an answer to what I asked and not what you are trying to do/explain? I need the numbers to replace image-files, or other type of files. I understand that you are a 1000-times better programmer, but in this case absolutely not helpfull. 
I found out how to read the remote-textfile and here's the code if someone can use it.
vb.net Code:
Imports System.Net Dim GetRemoteValue As New WebClient() Dim txtResult As String = GetRemoteValue.DownloadString ("http://www.nameofserver.com/test.txt") MsgBox(txtresult)
Now I need to compare the values with the local file.
-
Jul 20th, 2009, 09:53 AM
#6
Re: Compare textfile from server with local and download
Um... your code downloads the file just like jmcilhinney said you would have to!
You could kinda do it without downloading it but you'd need to implement a webservice to get specific lines of the file, and you're much better off just downloading it (unless its a huge file)
Last edited by keystone_paul; Jul 20th, 2009 at 09:56 AM.
-
Jul 20th, 2009, 10:02 AM
#7
Thread Starter
PowerPoster
Re: Compare textfile from server with local and download
Ok, but why the difficult answer and no example at all.
Nah File is only 1kb. Thanks Paul
-
Jul 20th, 2009, 10:09 AM
#8
Re: Compare textfile from server with local and download
Can't you just take a look at the last modified date and see if there's a difference between the local and remote versions of the file?
(VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.
-
Jul 20th, 2009, 10:13 AM
#9
Re: Compare textfile from server with local and download
I think he was clarifying your requirements as you said you wanted to do a comparison before downloading the file.
Some people like to check that the requirement is what they think it is (and if necessary suggest better ways of doing it) before embarking on a long description of something that may be inappropriate.
Its not necessarily a bad idea!
-
Jul 20th, 2009, 10:24 AM
#10
Re: Compare textfile from server with local and download
I find it interesting that people come here and ask others to provide an example of something as common as downloading a file. I'm fairly sure that there would already be plenty of examples of downloading a file already available, so I can only assume that an example is not really what is wanted but rather a turnkey solution. I tried to address the desire that was expressed in the original post: to compare the files without downloading first.
To that end, I provided you with the solution for comparing the files: create an MD5 hash. There's no need for me to provide the code because code examples already exist on the web. You didn't know what to look for before; now you do. A Google search for md5 hash .net is all that's required to find it.
Many people post here because they don't know what to search for so they can't find the information that already exists. If we provide the key words to allow them to search effectively and find that existing information then that's helping.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|