1

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;
    }
}
4

1 に答える 1

1

2つの可能性があると思います。次のようにストリームをフラッシュしてください。

using (System.IO.StreamWriter file = new System.IO.StreamWriter("somefile")
{
    //write to the stream
    file.Flush();
}

また、セッションに値があることを確認していますか:

HttpContext.Current.Session["UploadPath"]

常に入力されていますか、それともセッションから失われていますか? ロジックを分割して、次のように設定されていることを確認します。

string uploadPath = HttpContext.Current.Session["UploadPath"];
if (!string.IsNullOrEmpty())
{
    //write to the file
}
于 2012-09-10T16:27:24.043 に答える