Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting error 405 method not allowed when trying to "POST" a .txt file to a directory on my IIS 6 server with .Net webclient

Posted on 2006-11-08
5
Medium Priority
?
1,181 Views
Last Modified: 2012-08-14
I need to be able to download and upload some text files to a directory on our IIS web server. I can't use ftp because of firewall restriction so it has to be http. I can connect and download the files using the .Net webclient.DownloadFile() just fine. But when I try to use the webclient.UploadFile() I get the "(405) method not allowed" error. The write permissions are enabled on the website. Is there some other permissions or a configuration change that I need to make on the website?
0
Comment
Question by:defranz
  • 2
5 Comments
 
LVL 3

Expert Comment

by:tang_tzuchi
ID: 17904690
Hi,

You can try to use the Put method instead of Post method to upload your file.
0
 
LVL 3

Expert Comment

by:tang_tzuchi
ID: 17904704
below was some reference for the similar problems.......

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=511698&SiteID=17
0
 

Author Comment

by:defranz
ID: 17909462
I had already tried the using the PUT option instead of the default POST among many other things. I had to do a lot of other reading and searching and I was able to figure out that the real problem was a 401 error which was causing the server to give me the 405 error.

I didn't have the time to add this to the question description last night, but here is what the program is doing.

It is a remote program on one of our remote locations. It is automatically started and downloads the text files from our server to the remote PC. Then it imports the text files into the database and does the processing that it needs to. When it is done it uploads the response text files back to our server. The folder on the server is secured and the site is not browseable so that you would have to know that the folder exists in order to upload to it for security reasons.

The problem was that I was not assigning any headers to the webclient and the server was not recognizing the webclient as a recognized program and I think it was dropping the session and credentials after it initially logged in. After checking the logs on the server I noticed that it would initially login OK and then when I tried to post it would give me two different 401 errors and then the 405 because it didn't have the security to write to the folder. I did have to use the "PUT" method though. The "POST" method will not work.

Here is the general C# code that I used so that others who encounter this problem will hopefully have to do less searching.

To upload:

// setup the webclient
WebClient Client = new WebClient ();
NetworkCredential myCredentials = new NetworkCredential("username","password"); // security credentials
Client.Credentials = myCredentials;
Client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

// upload the file                  
byte[] responseArray = Client.UploadFile("http://some server name/name of the file after it is uploaded to the server","PUT",@"location of the file to upload");

// to download just use Client.DownloadFile() instead

Have a great day. Mine just got better! :)
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17964660
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Loops Section Overview

916 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