{
string targetDir = targetFolder + @"\" + folder;
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);
FtpWebRequest reqFilename = (FtpWebRequest)WebRequest.Create(serverUri);
reqFilename.Credentials = nc;
reqFilename.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Credentials = nc;
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
try
{
//FtpWebResponse resFilename = (FtpWebResponse)resFilename.GetResponse();
FtpWebResponse resFilename = (FtpWebResponse)reqFilename.GetResponse();
StreamReader file = new StreamReader(resFilename.GetResponseStream());
string sfileLine;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
StreamReader dir = new StreamReader(response.GetResponseStream());
List
Regex rgdir = new Regex("
//Regex rgfile = new Regex(@"(\b\S*)$");
Regex rgfile = new Regex(@"(\b*)$");
string aline;
string filename;
while (!dir.EndOfStream)
{
aline = dir.ReadLine();
sfileLine = file.ReadLine();
// filename = aline.Substring(aline.LastIndexOf("DIR") + 4).Trim();//rgfile.Match(aline).Groups[0].Value.Trim();
if (rgdir.Match(aline).Success)
{
filename = sfileLine;//aline.Substring(aline.LastIndexOf("DIR") + 4).Trim();//rgfile.Match(aline).Groups[0].Value.Trim();
subdir.Add(filename);
}
else
{
filename = sfileLine;//rgfile.Match(aline).Groups[0].Value.Trim();
}
// WriteLogFile(filename, MESSAGE_TYPE.INFO);
if (folder != null)
{
lstDest.Add(folder + @"\" + filename);
WriteLogFile(folder + @"\" + filename, MESSAGE_TYPE.INFO);
}
else
{
lstDest.Add(filename);
WriteLogFile(filename, MESSAGE_TYPE.INFO);
}
/* if (filename.Substring(filename.Length - 4).ToUpper() == ".ZIP")
{
// Console.WriteLine(folder + @"\" + filename);
WriteLogFile(folder + @"\" + filename, MESSAGE_TYPE.INFO);
// DownloadOneFile(serverUri + "/" + filename, targetDir + @"\" + filename);
// DeleteOneFile(serverUri + "/" + filename);
}*/
}
string sFolderName;
foreach (string s in subdir)
{
if(folder != null)
sFolderName = folder + @"\" + s;
else
sFolderName = s;
//ProcessFiles(serverUri + "/" + s, folder + @"\" + s);
ProcessFiles(serverUri + "/" + s, sFolderName);
}
resFilename.Close();
response.Close();
dir.Close();
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
}
No comments:
Post a Comment