{"id":187,"date":"2007-10-09T13:47:31","date_gmt":"2007-10-09T13:47:31","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2007\/10\/uploading_files_to_a_lamp_server_using_net-shtml\/"},"modified":"2007-10-09T13:47:31","modified_gmt":"2007-10-09T13:47:31","slug":"uploading_files_to_a_lamp_server_using_net-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/","title":{"rendered":"Uploading Files To A LAMP Server Using .NET"},"content":{"rendered":"<p>\nWe had to setup and run a webcam for the Q Awards red carpet earlier this week.\n<\/p>\n<p>\nThe original plan was to have an old Axis ethernet webcam, connected to a wifi network using a Dlink bridge. After a nightmare of not being able to get the Dlink to work, we gave up and went for a USB webcam connected to a laptop approach.\n<\/p>\n<p>\nI had to write some software to handle the capture of the image and the upload to the webserver. Because we wanted to do a few custom things on the way we weren&#8217;t able to use out of the box software.\n<\/p>\n<p>\nI&#8217;ll post on how to use a webcam with .NET another time. What I wanted to document was how to upload a file using .NET to a <acronym title=\"Linux Apache MySQL Perl\/PHP\/Python\">LAMP<\/acronym> server.\n<\/p>\n<p>\nIt turns out to be easier than I thought for .NET, one line of code can achieve this using the <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/dfkdh7eb(VS.80).aspx\">My.Computer.Network.UploadFile Method<\/a>.\n<\/p>\n<p>\nFor example, to upload <code>test.txt<\/code> to <code>http:\/\/www.robertprice.co.uk\/asp_upload.pl<\/code> we can do the following (in Visual Basic)&#8230;\n<\/p>\n<div class=\"code\"><code>My.Computer.Network.UploadFile(\"C:test.txt\",\"http:\/\/www.robertprice.co.uk\/asp_upload.pl\")<br \/>\n<\/code><\/div>\n<p>\nNow we need some code at the other end to store this upload. As I was building a webcam application, the uploaded file, an image in this case, was always overwritten.\n<\/p>\n<p>\nThe uploaded .NET file uses an bog standard <acronym title=\"HyperText Transfer Protocol\">HTTP<\/acronym> upload as described in <a href=\"http:\/\/www.faqs.org\/rfcs\/rfc1867.html\">RFC 1867<\/a>.\n<\/p>\n<p>\nIf we use <a href=\"http:\/\/www.perl.com\/\">Perl<\/a> to read this file, we can use the standard <a href=\"http:\/\/search.cpan.org\/dist\/CGI.pm\/\">CGI.pm<\/a> module to do most of the hard work for us.\n<\/p>\n<p>\nThe uploaded file is passed a parameter called <var>file<\/var>, so we can create a CGI object and get a reference to this using the <code>param<\/code> method. Once we have this, we can treat it as a filehandle and read the date off it. Then all we have to do is to write it out to a file.\n<\/p>\n<p>\nThe following code achieves this.\n<\/p>\n<div class=\"code\"><code>#!\/usr\/bin\/perl -w<br \/>\nuse strict;<br \/>\nuse CGI.pm;<br \/>\nmy $CGI = new CGI;<br \/>\nmy $file = $CGI->param('file');<br \/>\nopen(FILE, \"&gt;\/path\/to\/my\/file\/test.txt\") or die $!;<br \/>\nwhile(&lt;$file&gt;) {<br \/>\nprint FILE $_;<br \/>\n}<br \/>\nclose(FILE);<br \/>\nprint \"Content-type: text\/htmlnn\";<br \/>\nprint \"OKn\";<br \/>\n<\/code><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We had to setup and run a webcam for the Q Awards red carpet earlier this week. The original plan was to have an old Axis ethernet webcam, connected to a wifi network using a Dlink bridge. After a nightmare of not being able to get the Dlink to work, we gave up and went &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Uploading Files To A LAMP Server Using .NET&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[7,25,47,78],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-dev","tag-net","tag-http","tag-perl","tag-work"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Uploading Files To A LAMP Server Using .NET - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Uploading Files To A LAMP Server Using .NET - Robert Price\" \/>\n<meta property=\"og:description\" content=\"We had to setup and run a webcam for the Q Awards red carpet earlier this week. The original plan was to have an old Axis ethernet webcam, connected to a wifi network using a Dlink bridge. After a nightmare of not being able to get the Dlink to work, we gave up and went &hellip; Continue reading &quot;Uploading Files To A LAMP Server Using .NET&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2007-10-09T13:47:31+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Uploading Files To A LAMP Server Using .NET\",\"datePublished\":\"2007-10-09T13:47:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/\"},\"wordCount\":313,\"keywords\":[\".NET\",\"HTTP\",\"Perl\",\"Work\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/\",\"name\":\"Uploading Files To A LAMP Server Using .NET - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2007-10-09T13:47:31+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/uploading_files_to_a_lamp_server_using_net-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Uploading Files To A LAMP Server Using .NET\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Uploading Files To A LAMP Server Using .NET - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Uploading Files To A LAMP Server Using .NET - Robert Price","og_description":"We had to setup and run a webcam for the Q Awards red carpet earlier this week. The original plan was to have an old Axis ethernet webcam, connected to a wifi network using a Dlink bridge. After a nightmare of not being able to get the Dlink to work, we gave up and went &hellip; Continue reading \"Uploading Files To A LAMP Server Using .NET\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/","og_site_name":"Robert Price","article_published_time":"2007-10-09T13:47:31+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Uploading Files To A LAMP Server Using .NET","datePublished":"2007-10-09T13:47:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/"},"wordCount":313,"keywords":[".NET","HTTP","Perl","Work"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/","name":"Uploading Files To A LAMP Server Using .NET - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2007-10-09T13:47:31+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/uploading_files_to_a_lamp_server_using_net-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Uploading Files To A LAMP Server Using .NET"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}