我有一个小的导入例程,它从 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);
}
}
}
先感谢您