Я использую следующий код для загрузки ZIP-файла из Каталога (например, "hedrabad") с ftp-сервера.
try {
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(Procedures.ftpurl);
ftpRequest.Credentials = new NetworkCredential(Procedures.ftpuser, Procedures.ftpPassword);
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
List<string> directories = new List<string>();
string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
directories.Add(line);
line = streamReader.ReadLine();
}
streamReader.Close();
using (WebClient ftpClient = new WebClient())
{
ftpClient.Credentials = new System.Net.NetworkCredential(Procedures.ftpuser, Procedures.ftpPassword);
for (int i = 0; i <= directories.Count - 1; i++)
{
//if (directories[i].Contains("."))
//{
if (directories[i].ToString() == "Hyderabad")
{
log.Info("File Downloding Start : " + DateTime.Now.ToString("HH:mm ss"));
if (!Directory.Exists(OGSync.FTPPath + "\\Backups\\" + directories[i].ToString()))
{
Directory.CreateDirectory(OGSync.FTPPath + "\\Backups\\" + directories[i].ToString());
}
//string path = Procedures.ftpurl;
string path = Procedures.ftpurl + directories[i].ToString();
string trnsfrpth = OGSync.FTPPath + "Backups\\" + directories[i].ToString();
//string trnsfrpth = @"E:\\Test\" + directories[i].ToString();
ftpClient.DownloadFile(path, trnsfrpth);
//ftpClient.DownloadFile(path, @"C:\file.zip");
}
// }
}
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
return true;
}
Я получаю следующую ошибку, которую пыталсяно не удалось решить. Пожалуйста, любой может дать представление о том, как решить эту проблему.
Исключение: доступ к пути 'E: \ Zipfils \ Backups \ Hyderabad' запрещен.
Внутреннее исключение: Доступ к пути 'E: \ Zipfils \ Backups \ Hyderabad' запрещен.
StackTrace: в System.Net.WebClient.DownloadFile (адрес Uri, строковое имя файла) в OGServerSync.ServerSync.Downloadfile () вE: \ Модульный код и установщик \ OGServerSync \ OGServerSync \ ServerSync.cs: строка 64
Сообщение: во время запроса WebClient возникла исключительная ситуация.