我有一个小的导入例程,它从ftp源获取数据,解析它们并使用lint-to-sql将数据写入数据库。除了部分之外,这一切都完美无缺,即正在下载的文件不会在本地保存。
该程序遵循以下步骤:
文件在适当的文件夹中创建,但大小为0字节。 我哪里出错了?
代码:
FtpWebResponse responseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse();
try
{
using (Stream responseStream = responseFileDownload.GetResponseStream())
{
using (FileStream writeStream = new FileStream(localPath + "\\downloads\\" + FtpListing[i], FileMode.Create))
{
//data which is not downloaded, already exists as a flatfile locally
//write data from responsestream to db
using (var reader = new StreamReader(responseStream))
{
//ignore first line
string headline = reader.ReadLine();
#region Linq-To-Sql logic | Parsing
List<Messwert> fooList = new List<Messwert>();
//read rest of csv
using (var context = new DataContext())
{
//Logic edited out
//context.SubmitChanges();
}
}
#endregion
responseStream.Position = 0;
responseStream.CopyTo(writeStream);
}
}
}
提前谢谢