0

I wants to upload pdf files to ftp server. I have written like this.

    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();
}  

when run this code in local host it works properly.! but when try it on remote host, it shows an error "System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." I have set

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

I have no permission for make any changes on ftp server like " set the application pool to "Load User Profile Wht else to do?? please help

ARATHY
  • 349
  • 5
  • 13
  • 29
  • What have you done to test? Can you manually sFTP a file? – dcaswell Aug 27 '13 at 04:22
  • i have uploaded all my aspx pages to ftp server through filezilla. and run the project with the ftp link @user814064 – ARATHY Aug 27 '13 at 04:25
  • There's working code here: http://stackoverflow.com/questions/1080442/how-to-convert-an-stream-into-a-byte-in-c – dcaswell Aug 27 '13 at 04:30
  • I can print fs.length using this code, i have the same problem with when making a folder on ftp . @ user814064 – ARATHY Aug 27 '13 at 04:57

0 Answers0