问题描述
有上传文件到FTP的功能。手动运行程序,可以正常上传到FTP.如果用windows计划任务来自动运行程序,就会出现不能上传文件的提示。。。publicstaticvoidUploadFile(){foreach(ReportInforiinReportInfoList){try{stringfilename=ri.ReportName+".xls";stringftpServerIP="WWWWWW";FileInfofileInf=newFileInfo(filename);stringuri="ftp://"+ftpServerIP+"/"+fileInf.Name;FtpWebRequestreqFTP;reqFTP=(FtpWebRequest)FtpWebRequest.Create(newUri("ftp://"+ftpServerIP+"//"+ri.ReportFTPPath+"//"+fileInf.Name));reqFTP.Credentials=newNetworkCredential("USERNAME","PASSWORD");reqFTP.KeepAlive=false;reqFTP.Method=WebRequestMethods.Ftp.UploadFile;reqFTP.UseBinary=true;reqFTP.ContentLength=fileInf.Length;intbuffLength=2048;byte[]buff=newbyte[buffLength];intcontentLen;FileStreamfs=fileInf.OpenRead();Streamstrm=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();Console.WriteLine("UploadtoFTP>>>"+ri.ID+"_"+ri.ReportName+"<<<Done!!!");WriteLogs("UploadtoFTP>>>"+ri.ID+"_"+ri.ReportName+"<<<Done!!!");}catch(Exceptionex){Console.WriteLine("Errorinuploading>>>"+ri.ID+"_"+ri.ReportName+"!!!");WriteLogs("Errorinuploading>>>"+ri.ID+"_"+ri.ReportName+"!!!");}finally{}}}
解决方案
解决方案二:
提示啥,,,,,,,,,