测试提出代发工资模块上传加密文件报错,在vitual studio设置断点.定位到方法
corFileList.Add(upFile2);
j++;
payrollFtp.Upload(upFile);//上传文件的绝对路径(包含扩展名)
upload方法细节如下:
/// /// 上传
///
///
public void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = ftpURI + fileInf.Name;
System.Net.FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
//20110905 zxy 创建上传到ftp server 文件的文件流
FileStream fs = fileInf.OpenRead();
try
{
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
strm.Close();
fs.Close();
}
catch (Exception ex)
{
//Insert_Standard_ErrorLog.Insert("FtpClient", "Upload Error --> " + ex.Message);
throw new CoreBusinessException(99999L, "文件上传至ftp服务器时出现异常,请检查ftp服务器是否配置正确!", new string[] { });
}
}
后经分析,发现FTP服务器目录被我不小心移动了,导致上传找不到上传目录故报错
--摘录下ftpwebrequest类示例
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-709854/,如需转载,请注明出处,否则将追究法律责任。