views:

16

answers:

2

My code can be found here http://stackoverflow.com/questions/3604864/c-asp-net-ftp-error I am trying to download a file from an FTP server when I try to 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.

A: 

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!

kbrimington
and that's correct again thanks for your help 2x now in a row kbrimington. :)
h34dhun73r
@h34dhun73r - My pleasure. Good luck!
kbrimington
A: 

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.

Wyatt Barnett
Sorry if it wasn't clear it was going in my user folder, but the reason it wasn't working was my poorly formatted fileStream. I gave access to all users to see if VS was impersonating a user I was not on(from google) and that was not working. However both problems will return the same error so it can be a bit ambiguous which will be confusing to most people who google the error.
h34dhun73r