ASP.NET Unauthorized access when downloading from fTP
My code can be found here c# asp.net FTP Error I am trying to download a file from an FTP server when I try t开发者_StackOverflow中文版o download it it says I do not have access I have been googling this all morning and have not had any luck. I went to the designated folder and added Everyone with full permissions hoping I was missing a user and that did not work. I tried giving full permissions to myself, Anonymous user, network service, and a few other users that I have found. I have tried using
<identity impersonate="true" />
and
<identity impersonate="true" userName="myfullusername" password="mypassword"/>
I am still not having any luck the full error I get is:
System.UnauthorizedAccessException: Access to the path 'C:\Users\myname\Documents' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
any help I get is greatly appreciated Thank you all.
I suspect the error is due to creating a file stream out of a path that is a folder. Check the line where you construct your FileStream
with a debugger to see what is getting passed in.
Here is an example I ran on my machine:
// "Access to the path 'C:\users\myid\Documents' is denied."
var nostream = new System.IO.FileStream(@"C:\users\myid\Documents", FileMode.Create);
// OK
var okstream = new System.IO.FileStream(@"C:\users\myid\Documents\myfile.txt", FileMode.Create);
By the by, and you may already know, you can conveniently combine paths without having to worry about the direction of the slash, or whether the left-hand-side has a trailing slash, using System.IO.Path
.
Path.Combine(@"C:\users\myid\Documents", "myfile.txt");
I hope this helps. Good luck!
Doing things inside a user profile when you are not the user is generally a bit tricky -- there are a few more security settings defending it than giving Everyone access. Is there any reason it needs to be in your Documents folder or can it land somewhere else on the disk.
精彩评论