Results 1 to 4 of 4

Thread: [RESOLVED] FTP Upload Error

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Resolved [RESOLVED] FTP Upload Error

    I can't get this ftp upload file function I got from msdn to work:

    Code:
            private static void uploadFile(string FTPAddress, string filePath, string username, string password)
            {
                //Create FTP request
                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + Path.GetFileName(filePath));
    
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(username, password);
                request.UsePassive = true;
                request.UseBinary = false;
                request.KeepAlive = false;
    
                //Load the file
                FileStream stream = File.OpenRead(filePath);
                byte[] buffer = new byte[stream.Length];
    
                stream.Read(buffer, 0, buffer.Length);
                stream.Close();
    
                //Upload file
                Stream reqStream = request.GetRequestStream();
                reqStream.Write(buffer, 0, buffer.Length);
                reqStream.Close();
            }
    I get an error on this line:

    Stream reqStream = request.GetRequestStream();

    saying: Error 550, Permissions denied

    Which is not a C# error, but an FTP error from my ftp server stating that I need more permissions, but I already have full and if I log onto the ftp in another client I can upload files to any directory.

    Therefore something must be wrong with the code, anyone that got a clue?

  2. #2

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: FTP Upload Error

    Solved.

  3. #3
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: [RESOLVED] FTP Upload Error

    You mind sharing how?
    Delete it. They just clutter threads anyway.

  4. #4

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: [RESOLVED] FTP Upload Error

    Of course
    Actually there was nothing wrong with the code, just the way I passed the parameters to the function

    As I had tried writing my own upload function but not suceeded before, that lead to me passing the "string FTPAdress" wrong.

    When I got the error I wrote about I passed it as such:

    "ftp://mysite.com/myfiles/file.jpg"

    But then I realised that the function already merged the filename with the path in the code, I didn't have to do it myself so the proper input was this:

    "ftp://mysite.com/myfiles/"

    So that was the error I got and the problem I made and now it works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width