0

我当前的项目有问题,它是关于将文件上传到文件夹共享,我在 localhost 中尝试过,它成功了,但是在将它部署到服务器中的 IIS 后,它失败了,我只是收到这样的错误消息: 在此处输入图像描述

我该如何解决这个问题?

这是我当前的代码:

if (file1.HasFile)
{
bool exists = System.IO.Directory.Exists(Url +"/"+ emp_id);
if (!exists)
{
System.IO.Directory.CreateDirectory(Url + "/"+ emp_id);
}
file1.SaveAs(Server.MapPath("TemporaryFile/" + filename + ext));
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp:"+IPUrl);
ftp.Credentials = new NetworkCredential(UserName1, Password1);
ftp.KeepAlive = true;
ftp.UseBinary = true;

FtpWebRequest ftp2 = (FtpWebRequest)FtpWebRequest.Create("ftp:"+Url+"/" +emp_id+"/"+ filename + ext);
ftp2.Credentials = new NetworkCredential(UserName,Password );
ftp2.KeepAlive = true;
ftp2.Method = WebRequestMethods.Ftp.UploadFile;
Stream stream = ftp2.GetRequestStream();
string FilePath = System.IO.Path.GetFileName(file1.PostedFile.FileName);
FileStream file = File.OpenRead(Server.MapPath("TemporaryFile/" + filename + ext));

int length = 1024;
byte[] bytebuff = new byte[length];
int bytesRead = 0;

do
{
bytesRead = file.Read(bytebuff, 0, length);
stream.Write(bytebuff, 0, bytesRead);
}
while (bytesRead != 0);

file.Close();
stream.Close();
}
4

0 回答 0