access denied while writing file  
Author Message
Spoofer





PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

Hello

I have a question. I 'm working on a small ftp client program.
But when i try to download a file to a path for example c:\temp i get access denied.

How can i solve this


.NET Development35  
 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

  • please post the code

  • make sure you DO have write permission to that folder you are writing to

  • tried downloading it to a different location What happens



  •  
     
    Spoofer





    PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

    I already tried downloading it to another path. Even the parent directory of the program.

    I'm running this under admin accound, so that should cover the write premission.

    Don't think there is anything wrong with the code.
    Isn't this some kind op Microsoft to prevent againts malicious file download or something
    Can't i just set a parameter.. i dunno.

    My code is ok, just create socket and download the file, same as upload (which works perfectly :s)

     
     
    ahmedilyas





    PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

    no....

    you may say your code is perfect but it maybe full of bugs and in order for us to help you, please supply some code - perhaps you are writing the file incorrectly or something who knows until we can see the code, nothing much we can suggest.

    regardless of running it under the admin account or not, if your directory has readonly permission, you can't write to the folder at all.



     
     
    Spoofer





    PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

    This is the download code:

    public void download(string remFileName,string locFileName,Boolean resume)
    {
    if(!logined)
    {
    login();
    }

    setBinaryMode(true);

    Console.WriteLine("Downloading file "+remFileName+" from "+remoteHost + "/"+remotePath);

    if (locFileName.Equals(""))
    {
    locFileName = remFileName;
    }

    if(!File.Exists(locFileName))
    {
    Stream st = File.Create(locFileName);
    st.Close();
    }

    FileStream output = new
    FileStream(locFileName,FileMode.Open);

    Socket cSocket = createDataSocket();

    long offset = 0;

    if(resume)
    {

    offset = output.Length;

    if(offset > 0 )
    {
    sendCommand("REST "+offset);
    if(retValue != 350)
    {
    offset = 0;
    }
    }

    if(offset > 0)
    {
    if(debug)
    {
    Console.WriteLine("seeking to " + offset);
    }
    long npos = output.Seek(offset,SeekOrigin.Begin);
    Console.WriteLine("new pos="+npos);
    }
    }

    sendCommand("RETR " + remFileName);

    if(!(retValue == 150 || retValue == 125))
    {
    throw new IOException(reply.Substring(4));
    }

    while(true)
    {

    bytes = cSocket.Receive(buffer, buffer.Length, 0);
    output.Write(buffer,0,bytes);

    if(bytes <= 0)
    {
    break;
    }
    }

    output.Close();
    if (cSocket.Connected)
    {
    cSocket.Close();
    }

    Console.WriteLine("");

    readReply();

    if( !(retValue == 226 || retValue == 250) )
    {
    throw new IOException(reply.Substring(4));
    }

    }

    The login procedure is ok, so no problems there.
    Then i call this function in my main program like this:

    locPad = "c:\test";
    remPad = "/xml" + xmlfile;
    ftp.setBinaryMode(true);
    ftp.download(remPad,locPad);

    I gave myself on this test folder , full control, dunno whats wrong :s

    Thanx in advance



     
     
    Spoofer





    PostPosted: .NET Framework Networking and Communication, access denied while writing file Top

    locPad = "c:\\test" + xmlfile;
    remPad = "/xml" + xmlfile;
    ftp.setBinaryMode(true);
    ftp.download(remPad,locPad);

    found the solution myself. Had to be like above