Results 1 to 13 of 13

Thread: [RESOLVED] dynamically check version of exe file in FTP - VB.Net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Resolved [RESOLVED] dynamically check version of exe file in FTP - VB.Net

    to find version of an exe, i use this code
    Code:
    Dim FileProperties As FileVersionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath)
    Textbox1.Text = FileProperties.FileVersion
    How come we find a version of an exe that's uploaded in FTP? i need the version of an exe that's already there in FTP. i know the path where the exe file is saved in FTP.

    if you have any idea, please help me...

    Thanks in advance...

  2. #2
    Addicted Member
    Join Date
    Jan 2009
    Posts
    216

    Re: dynamically check version of exe file in FTP - VB.Net

    In my application I include version into file name then I use .ListDirectory to get files list and extract version from the name
    vb.net Code:
    1. wtheFTP.Method = WebRequestMethods.Ftp.ListDirectory

    Hope this help.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    Thanks mrjohn for your reply...

    so we cannot get version number of an exe from FTP.

    if you include version into file name, then how come you check the exact file from .ListDirectory.

    what i'm trying to do is, i need to check the version number of exe in FTP and check version number of exe in local machine. if it's different, then need to download exe from FTP.

    Thanks in advance.

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: dynamically check version of exe file in FTP - VB.Net

    FTP protocol provides little help for that.
    In order to get the version either place it in the file name or place some other file on the ftp server. It can contain the current version in its name (the wastest way).
    To update you should place the executable on the server and update the version information file.
    I've used a similar approach with the only difference that I placed 'version.txt' file on the server and put the version inside. It was only after when I realized that I could get by without downloading by simply looking for a filename that fits some pre-determined pattern.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    thanks cicatrix for your reply...

    so in order to find the version number, i need to create 'version.txt' in FTP and put exe's version inside that. and when i want to check version number from FTP, then download version.txt file and read the version number.

    That's what you mentioned? is that right?

    Thanks in advance...

  6. #6
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: dynamically check version of exe file in FTP - VB.Net

    Either like that, or simply put a file ver0001 on the ftp folder (version 1) then change it to ver0002 (version 2), etc.
    In this case you wouldn't even have to download it - you can read version right from the file name.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    thanks cicatrix for your reply.

    i will try that and will let you know about that.

  8. #8
    Addicted Member
    Join Date
    Jan 2009
    Posts
    216

    Re: dynamically check version of exe file in FTP - VB.Net

    You're welcome !
    We have files like this :
    myAPP_1_0_1_69.exe

    vb.net Code:
    1. wtheFTP = CType(System.Net.WebRequest.Create(wFTPupdPath), Net.FtpWebRequest)
    2.             wtheFTP.Credentials = New NetworkCredential(wFTPUsr, wFTPsw)
    3.             wtheFTP.Method = WebRequestMethods.Ftp.ListDirectory
    4.  
    5.             Dim listResponse As FtpWebResponse = CType(wtheFTP.GetResponse, Net.FtpWebResponse)
    6.  
    7.             Dim reader As StreamReader = New StreamReader(listResponse.GetResponseStream())
    8.             While reader.Peek >= 0
    9.                 wrLN = reader.ReadLine
    10.  
    11.                 If wrLN.ToLower.StartsWith(Me.wAppMsk.ToLower) Then Me.wstrVerFTP = wrLN
    12.             End While
    13.             If Not (reader Is Nothing) Then
    14.                 reader.Close()
    15.                 reader.Dispose()
    16.             End If
    17. .....................
    18.  
    19.  Me.wstrVerFTP = Me.wstrVerFTP.Substring(10, Me.wstrVerFTP.Length - 10).Replace(".exe", "")
    20.  
    21.         Dim wArrTmp() As String = Me.wstrVerFTP.Split("_"c)
    22.         If wArrTmp.Length = 4 Then
    23.  
    24.             wVer_Maj = CInt(wArrTmp(0))
    25.             wVer_Min = CInt(wArrTmp(1))
    26.             wVer_Bui = CInt(wArrTmp(2))
    27.             wVer_Rev = CInt(wArrTmp(3))
    28.         End If
    So with .ListDirectory you get a list of files in ftp directory,then you get the file name wanted :
    vb.net Code:
    1. ....
    2. If wrLN.ToLower.StartsWith(Me.wAppMsk.ToLower) Then Me.wstrVerFTP = wrLN
    ...
    then extract version from the name as above

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    Attached Class used for downloading files from FTP.

    the exe name is getting too big. so instead of adding the version number in exe name, i will create a text file in that folder that contains verison number. so i can check this .txt file name to get version number.

    for example: the text file name is going to be Ver.1.0.0.34.txt. 1.0.0.34 is version number, that keeps on change.

    is there a way i can check the file that starts with "Ver" and ends with ".txt". so i can find the version number.

    how come i check the file name from FTP?

    if you have any idea, please let me know.

    Thanks in advance...
    Attached Files Attached Files

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    Thanks for your help. i tried the code you mentioned.

    Code:
    wtheFTP = CType(System.Net.WebRequest.Create(wFTPupdPath), Net.FtpWebRequest)
    wtheFTP.Credentials = New NetworkCredential(wFTPUsr, wFTPsw)
    wtheFTP.Method = WebRequestMethods.Ftp.ListDirectory
    and import
    Code:
    Imports System.Web
    Imports System.Net
    Imports System.Net.WebRequest
    but it says "Type FTPWebREquset is not declared".
    also "Type WebRequestMethods is not declared".
    also "Type FtpWebResponse is not declared".

    whether I'm missing any declarations??? if you have any idea what's wrong with my code, please let me know.

    Thanks in advance.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: dynamically check version of exe file in FTP - VB.Net

    Thanks everyone for your help

    in the attached file, function GetFileList there is a line

    Code:
    mess = m_sMes.Split(seperator)
    mess is an array of string:

    So if the fucntion GetFileList you are reading the file names into the array 'mess'. So you need a new function to get the version, you already have the filenames in a string array. Pass 'mess' array into a function to loop through the array and do some string compair to find the file you need.

    Code:
       Public Function GetVerFile(ByVal mess() As String)
            Dim VerFileName As String
            For Each strfile In mess
                If strfile.SubString(0, 3) = "Ver" And strfile.Substring(strfile.length - 3, 3) = "txt" Then
                    ''do some code here.  If code is here then strfile must start with 'Ver' and end with 'txt'. This is persuming that the names returned in the array have the extension on the end.
                End If
            Next
            Return VerFileName
        End Function

  12. #12
    Addicted Member
    Join Date
    Jan 2009
    Posts
    216

    Re: dynamically check version of exe file in FTP - VB.Net

    I've created a new project and with this import :
    vb.net Code:
    1. Imports System.Net
    there is no error there
    vb.net Code:
    1. Dim wtheFTP As FtpWebRequest
    2.         Dim wpWebLocation, wpUsr, wpPsw As String
    3.  
    4.         Cursor.Current = Cursors.WaitCursor
    5.         wtheFTP = CType(System.Net.WebRequest.Create(wpWebLocation), Net.FtpWebRequest)
    6.         wtheFTP.Credentials = New NetworkCredential(wpUsr, wpPsw)
    7.  
    8.         wtheFTP.Method = WebRequestMethods.Ftp.ListDirectory

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: [RESOLVED] dynamically check version of exe file in FTP - VB.Net

    Thanks mrjohn for your reply.

    as you said i tried that code.

    but it says "Type FTPWebREquset is not declared".
    also "Type WebRequestMethods is not declared".
    also "Type FtpWebResponse is not declared".

    is it because i'm using vb.net 2003....

    Thanks in advance.

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