0

I'm creating a window service which will monitor the folder and upload files to server if any new files created. Here I'll have only web URL with virtual directory , created via IIS. Is it possible to upload a file to server only with URL.

I've tried using webclient to upload, its throwing error

The remote server returned an error: (405) Method Not Allowed.

This was my sample code tried:

  using (WebClient client = new WebClient())
  { 
       client.UploadFile(targetURL, phscialpath);
  }

Gave required permissions, to both IIS and physical path folder.

majita
  • 1,278
  • 14
  • 24
karthik
  • 11
  • 2
  • 1
    Yes it is possible but you will have to be more specific with your question. What have you tried and searched on google so far? – majita Feb 03 '20 at 04:39
  • using webclient I've tried to upload. its throwing the error. this was my code tried: client.UploadFile(targetURL, phscialpath); Also gave all the permissions, in both IIS and physical path folder. – karthik Feb 03 '20 at 05:00
  • keep on getting below error, even after gave all permissions. **The remote server returned an error: (405) Method Not Allowed**. – karthik Feb 03 '20 at 05:50
  • Check out https://stackoverflow.com/help/how-to-ask. All the info you are putting in the comments now should be in your question. It will help others to help you – majita Feb 03 '20 at 06:36
  • 405 means that IIS received the request but the http verb is not allowed, by default UploadFile uses POST. Can you check your IIS site if POST is allowed? See here for steps on how to get there: https://stackoverflow.com/a/41943229/2401021 – majita Feb 03 '20 at 07:41
  • thanks mate :) , it resolved my 405 error problem. But new error **The remote server returned an error: (500) Internal Server Error** thrown from server now. I've provided **IIS_IUSER** permission both read and write, on IIS and target folder also. Do I miss anything. – karthik Feb 03 '20 at 09:46
  • 500 means that there was an exception in server side code that you are running in IIS. It could be anything, without knowing your environment its will be near impossible to say what could be wrong. If you can debug the IIS code or find more detailed error messages you should edit this question or ask a new questions with as much detail as possible. – majita Feb 03 '20 at 12:14

1 Answers1

0

As far as I know, it's impossible to directly upload a file to the server directly.

Normally, we have two ways to upload the file to the IIS server. On way is hosting a application on the IIS and the application has the codes to save the file to the server.By using this way, you need have the enough knowledge to build the application by using ASP.NET , PHP or else. This will be a complex application.

The second way is using ftp. We will create a FTP application on the IIS server and then you could use FTP to transfer the file to the server. By using this way, you could directly save the file to the speicific folder by using url.

Details about how to build a IIS FTP server, you could refer to below aritlce: https://learn.microsoft.com/en-us/iis/publish/using-the-ftp-service/creating-a-new-ftp-site-in-iis-7

More details about how to transfer the file to the ftp by codes, you could refer to this answer.

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65