Skip to content

Implement 'rules' or 'wildcards' in GetListing #1246

Closed

Description

@javiercoob

FTP Server OS: Unix

FTP Server Type: hidrive.strato.com

Client Computer OS: Windows

FluentFTP Version: 46.02

Framework: 8.1 (I would have liked to run it under versión 4.0 or 4.5)

I'm new to github so I apologize if this is not the right way to do this.

It would be very useful to me if GetListing also had the posibility of Rules likewise DownloadDirectory or at least the posibility of using wildcards.

Of course I can filter it once I get the file listing but it could be more efficient if the server do it.

I wonder if there is any way of doing this or if it could be possible to implement it in a (not very) future versión.

Thanks in advance for your answer

Logs :


<paste VERBOSE logs here>

Activity

  1. robinrodricks commented on Apr 13, 2023

    @robinrodricks
    Owner

    Rules are a good idea, but keep in mind server will not do it. We do it on client side.

  2. javiercoob commented on Apr 14, 2023

    @javiercoob
    Author

    Hi! Thanks for answering so soon.
    About rules I supposed that was the problem.
    However, as long as I know, wildcards do work in server side. Couldn't it be nice Getlisting implement that?

  3. FanDjango commented on Apr 14, 2023

    @FanDjango
    Collaborator

    I would like to chime in here, if I may.

    RFC 959 (purposely?) does not go into any detail at all about the inferred meaning of filepath, pathname etc. when it describes the function of the LIST, RETR etc. etc. commands that take such a parameter.

    Thus, in the past, different FTP (RFC 959) server implementations have taken various liberties in implementing wildcards, and to which degree.

    The wildcard functionality that you can achieve today, currently depends entirely on the server that you are connecting to.

    Here is an example, using an up-to-date ProFTPD server.

    				client.Connect();
    				var item = client.GetListing("*.bin");
    				client.Disconnect();
    ...
    Command:  PWD
    Response: 257 "/home/mike" is the current directory [<1ms]
    >         GetListing("*.bin", Auto)
    Command:  PASV
    Status:   Waiting for response to: PASV
    Response: 227 Entering Passive Mode (192,168,1,109,154,73). [1ms]
    Status:   Connecting to IP #1= ***:39497
    Command:  MLSD /home/mike/*.bin
    Response: 550 /home/mike/*.bin: No such file or directory [<1ms]
    ...
    

    As you can see, on this server type, MLSD with wildcards is rejected.

    But:

    If you code

    				var item = client.GetListing("*.bin", FtpListOption.ForceList);

    you will get:

    ...
    Command:  LIST /home/mike/*.bin
    Response: 150 Opening BINARY mode data connection for file list [<1ms]
    +---------------------------------------+
    Listing:  -rw-r--r--   1 mike     mike            6 Sep 18  2022 /home/mike/test.bin
    -----------------------------------------
    

    and the list items are populated correctly.

    Therefore, I don't totally understand what you are asking for. Wildcards work, when the server supports them. You just need to find the right way to code it, and do some experiments to see what works and what does not.

    If your wish is to support wildcards client-side, i.e. for servers that do not support them, then okay, that is a possibly valid enhancement request, although you can easily handle that in your own code.

  4. FanDjango commented on Apr 14, 2023

    @FanDjango
    Collaborator

    Once more this is a good example why adding some example code and log output to show what you are trying to do, would have been a good idea, to save some time in speculation.

    However, as long as I know, wildcards do work in server side. Couldn't it be nice Getlisting implement that?

    It doesn't need to. The server does it. You just need to read up on GetListing and find out how to ask it to do the right thing.

  5. javiercoob commented on Apr 16, 2023

    @javiercoob
    Author

    HI FanDjango. Thanks for your answer.

    As first parameter in GetListing is path, I didn't think it was possible to add a wildcard.
    So, I've been doing the filtering in client side.

    My aim is to populate a treview node with the pdfs in a given path

    basically my code is ... (visual basic)


    **Private Sub Populate(node As TreeNode, path As String)

        Dim ftp = New FtpClient()
        Try
            ftp.Host = FTPSERVER
            ftp.Credentials = New NetworkCredential(HidriveUs, HidrivePw)
            ftp.AutoConnect()
    
            For Each item As FtpListItem In ftp.GetListing(path)
    
                             ' do  filtering to discard non pdf files    and pupulates the given node
            Next
            ftp.Disconnect()
       Catch ex As Exception     ' just in case
            Mensaje.Text = "Se produjo un error al recuperar los archivos de " + path+ ": " + ex.Message
        Finally
            ftp.Dispose()
        End Try
    
    End Sub**
    

    and that is working fine

    After your answer, I've tried ...

               **For Each item As FtpListItem In ftp.GetListing(path + "/*.pdf", FtpListOption.ForceList)**
    

    but then I get nothing.

    Just in case, I've also tried ...

            **ftp.SetWorkingDirectory(path)
    
            For Each item As FtpListItem In ftp.GetListing("*.pdf", FtpListOption.ForceList)**
    

    getting nothing again

    So far, I've started to believe my server doesn't allow wildcards.

  6. FanDjango commented on Apr 16, 2023

    @FanDjango
    Collaborator

    So far, I've started to believe my server doesn't allow wildcards.

    A log excerpt would tell us why...

    but then I get nothing.

    The answer of the server, the command selected by FluentFTP?

    Note that some servers don't even like a path, you might need to go to the working directory first, and then do a listing using only the wildcard filespec + FtpListOption.NoPath as well.

    So your second try needs: FtpListOption.ForceList | FtpListOption.NoPath

  7. FanDjango commented on Apr 16, 2023

    @FanDjango
    Collaborator

    Once more this is a good example why adding some example code and log output to show what you are trying to do, would have been a good idea, to save some time in speculation.

    In a (complete) log, we could also see the result of the FEAT command, tellings us about the capabilites of the server. Would make the discussion easier also.

  8. FanDjango commented on Apr 16, 2023

    @FanDjango
    Collaborator

    If all else fails, your VBasic loop to select the right files is nothing other than what we would also do - so there is no real advantage in coding this inside GetListing, it is of course nice to have...

  9. javiercoob commented on Apr 17, 2023

    @javiercoob
    Author

    I've made a trial console app and use the Config.LogToConsole = true option.
    LS: is not recognized
    LIST is recognized but response nothing
    MSLD without path or with a path that does not include wildcards works fine
    MSLD with a path that includes wildcards responses nothing

    I ended up acknowledging that I can't do the filtering at server side. I'll settle doing it at client side.

    I've actually appreciate your kind support. Thank you so much.

  10. FanDjango commented on Apr 17, 2023

    @FanDjango
    Collaborator

    What about NLST?

  11. changed the title [-]Asking for 'rules' or 'wildcards' in GetListing[/-] [+]Implement 'rules' or 'wildcards' in GetListing[/+] on Apr 17, 2023
  12. FanDjango commented on Apr 17, 2023

    @FanDjango
    Collaborator

    I have moved this to the Wiki: here

  13. robinrodricks commented on Apr 18, 2023

    @robinrodricks
    Owner

    I ended up acknowledging that I can't do the filtering at server side. I'll settle doing it at client side.

    As I said before.

  14. robinrodricks commented on Apr 18, 2023

    @robinrodricks
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址