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

Posted on 2008-11-13
Last Modified: 2013-11-07
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 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

Question by:praneethkavula
    LVL 3

    Expert Comment

    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.

    Author Comment

    My Ftp server have 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.

    LVL 3

    Expert Comment

    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?

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now