0
通常のフィルタ式(* .txt、Ben * .csv、*)を使用して、 。*)。IPを使用してFTP経由でフィルタリングされたファイルのリストを取得する方法* Works V8
私が現在持っている選択肢は、すべてのファイルとディレクトリのリスティングを取得し、それぞれをフィルタ式と比較してリターンする新しいリストを構築することです。
私の現在の方法はうまくいくが、もっとエレガントな方法があるのだろうかと思っている。ここで
は、ファイルリストを作成するためのいくつかの擬似コードです:
/// <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)
{
List<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;
}