批处理作业失败 - System.Net.WebException:操作已超时

时间:2017-03-23 14:01:43

标签: c#

    public void UploadToFTP(string sourceFile, string ftpFolderPath)
    {
        var fileInf = new FileInfo(sourceFile);
        var ftpPathSb = string.Format("ftp://{0}/{1}/{2}", _ftpInfo[Constants.FTPVariables.N_COL_FTP_KEY_HOST],
            ftpFolderPath, fileInf.Name);
        //create an ftp request
        var reqFtp = (FtpWebRequest) WebRequest.Create(new Uri(ftpPathSb));
        reqFtp.Method = WebRequestMethods.Ftp.UploadFile;
        reqFtp.Proxy = null;
        reqFtp.KeepAlive = false;
        reqFtp.UseBinary = true;
        reqFtp.Credentials = new NetworkCredential(_ftpInfo[Constants.FTPVariables.N_COL_FTP_KEY_ID],
            _ftpInfo[Constants.FTPVariables.N_COL_FTP_KEY_PW]);
        reqFtp.ContentLength = fileInf.Length;
        const int buffLength = 2048;
        var buff = new byte[buffLength];
        var fs = fileInf.OpenRead();
        try
        {
            // Stream to which the file to be upload is written
            var strm = reqFtp.GetRequestStream();

            // Read from the file stream 2kb at a time
            var contentLen = fs.Read(buff, 0, buffLength);

            // Till Stream content ends
            while (contentLen != 0)
            {
                // Write Content from the file stream to the
                // FTP Upload Stream
                strm.Write(buff, 0, contentLen);
                contentLen = fs.Read(buff, 0, buffLength);
            }

            // Close the file stream and the Request Stream
            strm.Close();
            fs.Close();
        }
  

错误详细信息:未处理的异常:System.Net.WebException:操作已超时。      在System.Net.FtpWebRequest.CheckError()      在System.Net.FtpWebRequest.GetResponse()      at NorthernTrust.DSE.Core.Services.Ftp.Ftp.DownloadFromFTP(String fileName,String ftpFolderPath)      at NorthernTrust.DSE.Core.Business.Controllers.FtpController.DownloadFromFTP(String fileName,String ftpFolderPath)      在NorthernTrust.DSE.DSEBatch.Console.Program.Main()

     

未处理的异常:System.Exception:抛出了类型'System.Exception'的异常。      at NorthernTrust.DSE.Core.Services.Ftp.Ftp.UploadToFTP(String sourceFile,String ftpFolderPath)      at NorthernTrust.DSE.Core.Business.Controllers.FtpController.UploadToFTP(String sourceFile,String ftpFolderPath)      at NorthernTrust.DSE.DSEBatch.Console.Program.LogMove(String fName)      在NorthernTrust.DSE.DSEBatch.Console.Program.Main()

0 个答案:

没有答案