Results 1 to 20 of 20

Thread: [2005] Getting list of files from a folder (FTP) [Urgent :(]

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    [2005] Getting list of files from a folder (FTP) [Urgent :(]

    Hello!
    Im making a software for our Counter-Strike Source server.
    I'd like to get all map files (.bsp files) from the map folder using the servers ftp adress.

    I tried using this code:
    VB Code:
    1. Dim folder As New IO.DirectoryInfo(ftpAdress & "/srcds_l/cstrike/maps/")
    2.         Dim files As IO.FileInfo() = folder.GetFiles("*.bsp")

    But it gives me the error "The given path's format is not supported."

    So what should I do? Any suggestions?

    Thanks in advance.
    Last edited by Atheist; Apr 28th, 2006 at 05:08 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [2005] Getting list of files from a folder (FTP)

    DirectoryInfo doesn't in fact support ftp type addresses. If you're still on .NET 2003 you'll have either have to shell the windows ftp utility or write your own warpper to the windows calls. I think .NET 2005 has the ftpWebRequest class in the System.Net or System.Web namespace
    Last edited by Mr.No; Apr 28th, 2006 at 12:47 PM.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP)

    ftpWebRequest...yeah ive seen that when i was havin a look around.
    Could you help me on how to use it?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [2005] Getting list of files from a folder (FTP)

    Could you help me on how to use
    Unfortunately no, I' still using VB.NET 2003 and haven't tried the ftpWebreqtest thing, I just read about its existence ..
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  5. #5

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP)

    ok...thanks anyways, I'll give it a good look.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    you need to use WebRequestMethods.Ftp.ListDirectoryDetails to list the contents of an ftp directory.

    a quick example i put together ....
    VB Code:
    1. [COLOR=Blue]Private Sub[/COLOR] Button1_Click([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Button1.Click
    2.         [COLOR=Blue]Dim[/COLOR] ftp [COLOR=Blue]As[/COLOR] FtpWebRequest = [COLOR=Blue]DirectCast[/COLOR](FtpWebRequest.Create("ftp://mirror.nl/disk2/tucows/"), FtpWebRequest)
    3.  
    4.         [COLOR=Green]'/// ************************
    5.         '///NOTE if you need to authenticate with username / password you would add the following 2 lines ...[/COLOR]
    6.         [COLOR=Green]'Dim cred As New NetworkCredential("username here", "password here")
    7.         'ftp.Credentials = cred
    8.         '/// ************************[/COLOR]
    9.  
    10.         ftp.AuthenticationLevel = Security.AuthenticationLevel.MutualAuthRequested
    11.         ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails
    12.         ftp.Proxy = [COLOR=Blue]Nothing[/COLOR]
    13.  
    14.         [COLOR=Blue]Dim[/COLOR] ftpresp [COLOR=Blue]As[/COLOR] FtpWebResponse = [COLOR=Blue]DirectCast[/COLOR](ftp.GetResponse, FtpWebResponse)
    15.        
    16.         '/// **** these 3 lines are NOT needed, just shows you a bit of the server logon messages you would see ...
    17.         Console.WriteLine(ftp.Headers.ToString)
    18.         Console.WriteLine(ftpresp.BannerMessage)
    19.         Console.WriteLine(ftpresp.Headers.ToString)
    20.         '/// ****
    21.  
    22.         [COLOR=Blue]Dim[/COLOR] sreader [COLOR=Blue]As New[/COLOR] IO.StreamReader(ftpresp.GetResponseStream)
    23.  
    24.         [COLOR=Blue]While Not[/COLOR] sreader.Peek = -1
    25.             [COLOR=Blue]Dim[/COLOR] ftpList [COLOR=Blue]As String[/COLOR]() = sreader.ReadLine.Split(" ")
    26.             [COLOR=Blue]Dim[/COLOR] ftpfile [COLOR=Blue]As String[/COLOR] = ftpList(ftpList.GetUpperBound(0))
    27.             Console.WriteLine(ftpfile)
    28.         [COLOR=Blue]End While[/COLOR]
    29.  
    30.  
    31.         ftpresp.Close()
    32.     [COLOR=Blue]End Sub[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    Thank you ALOT mate! You cant imagine how much i needed that code
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    Just one more thing:

    I had this code you gave me the click event of a button.
    I tried clicking the button several times with a small pause between each click and then this error message came popping up:

    The remote server returned an error: (500) Syntax error, command unrecognized.

    On the line marked in red:

    VB Code:
    1. Dim ftp As FtpWebRequest = DirectCast(FtpWebRequest.Create(ftpAdress & "/srcds_l/cstrike/maps/"), FtpWebRequest)
    2.  
    3.         '/// ************************
    4.         '///NOTE if you need to authenticate with username / password you would add the following 2 lines ...
    5.         'Dim cred As New NetworkCredential("username here", "password here")
    6.         'ftp.Credentials = cred
    7.         '/// ************************
    8.  
    9.         ftp.AuthenticationLevel = Security.AuthenticationLevel.MutualAuthRequested
    10.         ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails
    11.         ftp.Proxy = Nothing
    12.  
    13.         [COLOR=Red]Dim ftpresp As FtpWebResponse = DirectCast(ftp.GetResponse, FtpWebResponse)[/COLOR]
    14.  
    15.         '/// **** these 3 lines are NOT needed, just shows you a bit of the server logon messages you would see ...
    16.         Console.WriteLine(ftp.Headers.ToString)
    17.         Console.WriteLine(ftpresp.BannerMessage)
    18.         Console.WriteLine(ftpresp.Headers.ToString)
    19.         '/// ****
    20.  
    21.         Dim sreader As New IO.StreamReader(ftpresp.GetResponseStream)
    22.  
    23.         While Not sreader.Peek = -1
    24.             Dim ftpList As String() = sreader.ReadLine.Split(" ")
    25.             Dim ftpfile As String = ftpList(ftpList.GetUpperBound(0))
    26.             Console.WriteLine(ftpfile)
    27.             If ftpfile.Contains(".bsp") And Not ftpfile.Contains(".ztmp") Then
    28.                 lwMaps.Items.Add(ftpfile, 6)
    29.             End If
    30.         End While
    31.  
    32.  
    33.         ftpresp.Close()
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    well you should only click one time. but, is the ftp path remote? or local?
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  10. #10

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    Its remote.
    I have an option in a menu "Server maps", when its clicked it fires this code and lists all the maps, so it can be clicked several times
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  11. #11
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    make sure your ftp path is correct , it must be ftp://server path.com , NOT ftp://ftp.server path.com
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  12. #12

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    it is correct, i think.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    hmm I just changed the line:

    VB Code:
    1. Dim ftpresp As FtpWebResponse = DirectCast(ftp.GetResponse, FtpWebResponse)

    to:
    VB Code:
    1. Dim ftpresp As FtpWebResponse
    2.         Try
    3.             ftpresp = DirectCast(ftp.GetResponse, FtpWebResponse)
    4.         Catch ex As Exception
    5.             MsgBox(ex.Message)
    6.         End Try

    And now its working as it should. No error messages at all.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  14. #14

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    But I'd like to ask you one more thing while im still at it...

    Do you know how to erase a file on the ftp server?

    Very much appreciated. Thank you.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    you would use WebRequestMethods.Ftp.DeleteFile when doing the FtpWebrequest
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  16. #16

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    yeah i saw that there was something in there that looked good. But how do I use it?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  17. #17
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    specify the file you want in the request, eg
    FtpWebRequest.Create(ftpAdress & "/srcds_l/cstrike/maps/somefile.exe")
    the method ...
    ftp.Method = WebRequestMethods.Ftp.DeleteFile

    just use the same routine as getting the list.

    but ...
    you must have permission to delete the file.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  18. #18

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    aaah I understand. Yeah Ive got permission. Thank you alot youve made my day
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  19. #19

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,020

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    Still getting those error messages i mentioned in previous posts...It looks to me like its the server being a b*tch..
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  20. #20
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    268

    Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]

    I know this is an old thread, but I just ran across this while trying to do something along the same lines (I needed to make an app that would check this ftp site every day and make sure a certain file was there (because it gets automatically ftp'd)).
    When looping through the contents of the FTP site (and using this code), it would throw an error after returning about 20 items in the folder, saying 550: File not Found.
    If you cange:
    VB Code:
    1. While Not sreader.Peek = -1
    2.             Dim ftpList As String() = sreader.ReadLine.Split(" ")
    3.             Dim ftpfile As String = ftpList(ftpList.GetUpperBound(0))
    4.             Console.WriteLine(ftpfile)
    5.         End While
    to:
    VB Code:
    1. Do Until sreader.EndOfStream
    2.             ftpList = sreader.ReadLine.Split(" ")
    3.             ftpfile = ftpList(ftpList.GetUpperBound(0))
    4.             Console.WriteLine(ftpfile)
    5.         Loop
    Then it returns all items, atleast for me.

    Just posting this, incase someone else comes across this thread and has the same problem I did. Pretty simple fix, actually.

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