Results 1 to 10 of 10

Thread: [RESOLVED] Compare textfile from server with local and download

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [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.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Compare textfile from server with local and download

    Quote Originally Posted by Radjesh Klauke View Post
    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.
    Quote Originally Posted by Radjesh Klauke View Post
    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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:
    1. Imports System.Net
    2.  
    3. Dim GetRemoteValue As New WebClient()
    4. Dim txtResult As String = GetRemoteValue.DownloadString ("http://www.nameofserver.com/test.txt")
    5. MsgBox(txtresult)

    Now I need to compare the values with the local file.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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.

  7. #7

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    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>.

  9. #9
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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!

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width