我们遇到了一个问题,我们有一个函数被调用来创建 FTP 设置文件,但是有时这个函数从未被调用(因为 FTP 设置文件从不存在)并且这个问题是间歇性的。该函数在之后调用
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(UploadPath));
public bool GenerateFTPSettings()
{
try
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath((string)HttpContext.Current.Session["UploadPath"]) + @"\ftp_settings.ftp"))
{
file.WriteLine(string.Format("user {0}",ConfigurationManager.AppSettings["FTPUserName"]));
file.WriteLine(ConfigurationManager.AppSettings["FTPPassword"]);
file.WriteLine(string.Format("QUOTE SITE LRECL=80 RECFM=FB CY PRI={0} SEC={1}", ConfigurationManager.AppSettings["PRI"], ConfigurationManager.AppSettings["SEC"]));
file.WriteLine("BIN");
file.WriteLine(string.Format("put {0}\\NEW FILE'FTPP.Z.T.{1}.{2}.INT'", HttpContext.Current.Server.MapPath((string)HttpContext.Current.Session["UploadPath"]),
ConfigurationManager.AppSettings["FTPUserName"], ConfigurationManager.AppSettings["MailboxID"]));
file.WriteLine("QUIT");
}
return true;
}
catch (Exception ex)
{
ErrorHandler.WriteError(ex, "Upload");
return false;
}
}