开发者

How to retrieve a filtered list of files via FTP using IP*Works V8

开发者 https://www.devze.com 2023-03-27 06:28 出处:网络
Is there a simple way to retrieve a filtered list of files from an ftp server using a normal filter expression (*.txt, Ben*.csv, *.*).

Is there a simple way to retrieve a filtered list of files from an ftp server using a normal filter expression (*.txt, Ben*.csv, *.*).

The option I have at present is to retrieve a listing for all the files and directories and then iterate through them comparing each with the filter expression, building up a new list for return.

Whilst my current way would work, I'm wondering if there's a more elegant way to do it.

Here is some pseudo code for creating the file list:

    /// <summary>
    /// Get a list of files on the FTP server in the pre-specified remote dir
    /// </summary>
    /// <param name="wildCard">file filter, eg "*.txt"</param>
    /// <returns>list of files on server</returns>
    public List<string> ListFiles(string wildCard)
    {
        Lis开发者_开发问答t<string> result = new List<string>();

        try
        {
            // Instantiate the process object
            Ftp processor = new Ftp();

            processor.User = m_User;
            processor.Password = m_Pass;
            processor.RemoteHost = m_Server;
            processor.RemotePort = Convert.ToInt32(m_Port);

            // Connect to the server
            processor.Logon();

            // Ensure there is a connection
            if (processor.Connected == true)
            {
                //Retrieve the file list

                // Clear the remote file so that it's clear we aren't doing a transfer
                processor.RemoteFile = string.Empty;
                processor.ListDirectoryLong();

                DirEntryList filelist = processor.DirList;

                // Iterate through the returned listing from the remote server
                foreach (DirEntry entry in filelist)
                {
                    // Perform match on the file filter

                    // Ensure only files are added to the list

                    // Add the entry to the list
                }

                processor.Logoff();
            }
        }
        catch (Exception ex)
        {
            // Log the error
        }

        return result;
    }


The answer was easy but took some digging through the poor documentation provided by IP*Works!

In the example code, I'd cleared the RemoteFile property but should have actually set it as the filter.

0

精彩评论

暂无评论...
验证码 换一张
取 消