3
FTPロケーションからzipファイルをコピーする際のいくつかの問題を見つける。私はStreamReaderまたはStreamWriterの使用に何か問題があると思います。ここで FTPからZIPファイルをダウンロードし、ウェブサイト内のフォルダにコピーする
コードです://read through directory details response
string line = reader.ReadLine();
while (line != null)
{
if (line.EndsWith("zip")) //"d" = dir don't need "." or ".." dirs
{
FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://" + ftpHost + line); //new Uri("ftp://" + ftpServerIP + DestinationFolder + fileInf.Name));
downloadRequest.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FilesUser"], ConfigurationManager.AppSettings["FilesPass"]);
downloadRequest.KeepAlive = false;
downloadRequest.UseBinary = true;
downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile;
string folderToWrite = HttpContext.Current.Server.MapPath("~/Routing/RoutingFiles/");
string folderToSave = HttpContext.Current.Server.MapPath("~/Routing/");
StreamReader downloadRequestReader = new StreamReader(downloadRequest.GetResponse().GetResponseStream());
DirectoryInfo downloadDirectory = new DirectoryInfo(folderToWrite);
FileInfo file = new FileInfo(Path.Combine(downloadDirectory.FullName, line));
if (!file.Exists)
{
StreamWriter writer = new StreamWriter(Path.Combine(folderToWrite, line), false);
writer.Write(downloadRequestReader.ReadToEnd());
using (var downloadResponseStream = response.GetResponseStream())
{
}
}
}
}
それはそのセクションの底になる頃には、ファイルがコピーされますが、空であるので、私は正しくストリームを読んでいるとは思わないされていますzipファイル誰にでもアイデアはありますか?私は、FileStreamがZipファイルをダウンロードするのが良いという話を見たことがありますが、どちらもうまくいきませんでした。
ありがとうございました。
こんにちはTeletha - 進歩を遂げ、今というエラーをもたらしている:私は試してみて、行くとき「のZipEntry :: ReadDirEntry()悪い署名を」内容をループするためにZipファイルにコピーします。ダウンロードしたzipファイルをエクスプローラで試してみると、「圧縮されたフォルダ...は無効です」というエラーが表示されます。 Zipファイルには別のダウンロード方法は必要ありませんか? –
あなたは正しいです。通常のファイルで動作し、zipファイルでも動作すると想定していました。ごめんなさい。今すぐソリューションを見てください。 – Teletha
@ e-onこれでうまくいくはずです。以前のエラーで申し訳ありません。 – Teletha