[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1769
  • Last Modified:

File Access denied exception while uploading a file in the FTP Server

I am developing an application which will be used to upload the user files in to a FTP server.
Files are getting uploaded from the developer system to the server without raising any exception
Application is developed in asp.net 2.0 and hosted in a windows 2003 server, am attaching the code.
While uploading a file from the client system, fallowing exception is raised.

System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings\kb\Desktop\ddddddd.ppt' 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)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at System.Net.WebClient.OpenFileInternal(Boolean needsHeaderAndBoundary, String fileName, FileStream& fs, Byte[]& buffer, Byte[]& formHeaderBytes, Byte[]& boundaryBytes)
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
string strFTPURL = ConfigurationManager.AppSettings["FTPURL"];
string strFTPUserName = ConfigurationManager.AppSettings["FTPUserName"];
string strFTPPassword = ConfigurationManager.AppSettings["FTPPassword"];
System.Net.WebClient ftpClient = new System.Net.WebClient();
System.Net.NetworkCredential ftpCredentials = new System.Net.NetworkCredential(strFTPUserName, strFTPPassword);
ftpClient.Credentials = ftpCredentials;                
ftpClient.Proxy = null;
ftpClient.UploadFile(strFTPURL + strFileName, strSelectedFile);

Open in new window

  • 2
  • 2
1 Solution
The client system does not have sufficient rights for aspnet to access the folder that contains the file to be uploaded.
try giving the same permissions (add "aspnet" to the security on the folder) that are present on the development server.
also are you sure the path is the same on the development server? i.e 'C:\Documents and Settings\kb\Desktop' ??? (except for the profile name i.e kb)

i doubt that!
cross check and let me know.
praneethkavulaAuthor Commented:
My Ftp server have ASP.net installed in it, and the ASPNET account have full control on the FTP folder.
and ASPNET account has full access on the Web Application folder in deployment server.
string strFTPURL = "ftp://ftpserverIP/Uploads/";
Client selected the file from the file upload control is
"C:\Documents and Settings\kb\Desktop\ddddddd.ppt"
am changing the strFileName to
strFileName = "ddddddd.ppt"; using strFileName = Path.GetFileName(fuUploadFile.PostedFile.FileName);

so the destination file would be ftp://ftpserverIP/Uploads/ddddddd.ppt
and the source is "C:\Documents and Settings\kb\Desktop\ddddddd.ppt"

This application is live on internet so my client needs file uploading can be done from any where, so how can i set permissions on the client system.

is your application running under a specific account? try to get the user to upload the file from another location say from another drive.does it upload then? check your impersonation in configuration file.
try restarting your IIS once and check again. also, which permissions presently exist on the ftp?
praneethkavulaAuthor Commented:

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now