{"id":2712,"date":"2017-02-02T14:58:15","date_gmt":"2017-02-02T13:58:15","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=2712"},"modified":"2017-02-04T22:25:35","modified_gmt":"2017-02-04T21:25:35","slug":"posting-a-file-from-command-line-with-curl","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2017\/02\/posting-a-file-from-command-line-with-curl\/","title":{"rendered":"posting a file from command line with CURL"},"content":{"rendered":"<p>i needed to write a .bat script for windows to upload a log file. quick and nasty hack.. on the sending end:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncurl -F &quot;file=@%temp%\\someFileName.log;filename=nameToBePresented.log&quot; https:\/\/myserver\/in.php\r\n&#x5B;code]\r\n\r\nwhere in.php is:\r\n&#x5B;code]\r\n$fName = &quot;up\/&quot;.date(&quot;Ymd_His&quot;).&quot;_&quot;.uniqid();\r\n$cnt = 0;\r\nforeach($_FILES as $k=&gt;$f)\r\n  file_put_contents($fName.'_'.str_replace(&#x5B;'.','\\\\'],'',$f&#x5B;'name']).&quot;.&quot;.($cnt++).&quot;.body&quot;,file_get_contents($f&#x5B;'tmp_name']) );\r\necho 'ok';\r\n<\/pre>\n<p>looks straightforward, worked when i tested; but failed to upload in the production setup.<\/p>\n<p>on the http server\/PHP i was getting:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;Thu Feb 02 12:46:09.430384 2017] &#x5B;:error] &#x5B;pid 13273] &#x5B;client 58.4.5.6:21549] PHP Warning:  file_get_contents(): Filename cannot be empty in \/var\/www\/in.php on line 4\r\n&#x5B;Thu Feb 02 12:46:09.432869 2017] &#x5B;core:info] &#x5B;pid 13273] &#x5B;client 58.4.5.6:21549] AH00564: Request header field is missing ':' separator: }\r\n&#x5B;Thu Feb 02 12:46:09.432875 2017] &#x5B;core:info] &#x5B;pid 13273] &#x5B;client 58.4.5.6:21549] AH00567: request failed: error reading the headers\r\n<\/pre>\n<p>turned out that the log file was growing. curl at the beginning was sending header containing: <i>Content-Length: 1234577<\/i> yet later the file was overgrowing that size.<\/p>\n<p>instead of uploading the log file i&#8217;ve added one line to take a snapshot of it:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncopy %temp%\\someFileName.log %temp%\\someFileName.log.snap\r\ncurl -F &quot;file=@%temp%\\someFileName.log.snap;filename=nameToBePresented.log&quot; https:\/\/myserver\/in.php\r\n<\/pre>\n<p>now it works!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i needed to write a .bat script for windows to upload a log file. quick and nasty hack.. on the sending end: curl -F &quot;file=@%temp%\\someFileName.log;filename=nameToBePresented.log&quot; https:\/\/myserver\/in.php &#x5B;code] where in.php is: &#x5B;code] $fName = &quot;up\/&quot;.date(&quot;Ymd_His&quot;).&quot;_&quot;.uniqid(); $cnt = 0; foreach($_FILES as $k=&gt;$f) file_put_contents($fName.&#8217;_&#8217;.str_replace(&#x5B;&#8217;.&#8217;,&#8217;\\\\&#8217;],&#8221;,$f&#x5B;&#8217;name&#8217;]).&quot;.&quot;.($cnt++).&quot;.body&quot;,file_get_contents($f&#x5B;&#8217;tmp_name&#8217;]) ); echo &#8216;ok&#8217;; looks straightforward, worked when i tested; but failed to upload in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,51],"tags":[],"class_list":["post-2712","post","type-post","status-publish","format-standard","hentry","category-tech","category-unimportant"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/2712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=2712"}],"version-history":[{"count":3,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/2712\/revisions"}],"predecessor-version":[{"id":2715,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/2712\/revisions\/2715"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=2712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=2712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=2712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}