Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将pdf文件加载到ftp服务器时System.Security.SecurityException?_C#_Asp.net_Ftp - Fatal编程技术网

C# 将pdf文件加载到ftp服务器时System.Security.SecurityException?

C# 将pdf文件加载到ftp服务器时System.Security.SecurityException?,c#,asp.net,ftp,C#,Asp.net,Ftp,我想上传pdf文件到ftp服务器。我是这样写的 public void upload_pdf_file(string userName, string password, string test_id, string student_id) { string filename = Path.GetFileName(FileUpload1.FileName); System.Net.FtpWebRequest rq = (System.Net.FtpWebReque

我想上传pdf文件到ftp服务器。我是这样写的

    public void upload_pdf_file(string userName, string password, string test_id, string student_id)
{   

    string filename = Path.GetFileName(FileUpload1.FileName);
    System.Net.FtpWebRequest rq = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create("ftp://www.xxx.co/pdf/" + filename + "");
    rq.Credentials = new System.Net.NetworkCredential(userName, password);
    rq.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
    System.IO.Stream fs = FileUpload1.PostedFile.InputStream;
    byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);
    fs.Close();
    System.IO.Stream ftpstream = rq.GetRequestStream();
    ftpstream.Write(buffer, 0, buffer.Length);
    ftpstream.Close();
}  
当在本地主机上运行此代码时,它可以正常工作。!但在远程主机上尝试时,显示错误“System.Security.SecurityException:请求'System.Net.WebPermission,System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'类型的权限失败”。我已设置

`   <securityPolicy>
     <trustLevel name="Full"  policyFile="internal"/>
  </securityPolicy> ' 
`
' 

我没有权限在ftp服务器上进行任何更改,如“将应用程序池设置为”加载用户配置文件,还有什么要做??请帮助

您做了哪些测试?你能手动sFTP文件吗?我已经通过filezilla将我所有的aspx页面上传到ftp服务器。使用ftp链接@user814064运行项目这里有工作代码:我可以使用此代码打印fs.length,我在ftp上创建文件夹时也有同样的问题。@用户814064