I am trying to FTP multiple files from server (particular directory say /x/) to local directory. I know the names of files which i want to FTP, Is there a way to FTP all the files residing in the particular directory of server in one command like "mget()" command in unix.
Currently i am doing following thing
using (WebClient ftpClient = new WebClient())
{
ftpClient.Credentials = // credentials
ftpClient.DownloadFile("ftp://<ftp ip>//x//y//" + "x0.txt", @"D:\\test\\x\\" + "check" + "_a0.txt");
ftpClient.DownloadFile("ftp://<ftp ip>//x//y//" + "x1.txt", @"D:\\test\\x\\" + "check" + "_a1.txt");
ftpClient.DownloadFile("ftp://<ftp ip>//x//y//" + "x2.txt", @"D:\\test\\x\\" + "check" + "_a2.txt");
}
This makes FTP connection each time it wants to download/ make copy of file to local directory.
Even If i read the directory contents by following command
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
if (line.Contains("xyz"))
{
result.Append(line);
result.Append("\n");
}
line = reader.ReadLine();
}
and then download each file individually, it still makes call for each file to FTP to local directory. I am looking for something which can match the pattern like "wildcard" and download all files in one command that matches the pattern or wildcard.
Thanks in advance for all the help.
Thanks