1

I want to upload to my host via PowerShell.

But this is not possible for me and I face various obstacles. I came across the internet to find the answer

$uri = "http://myurl.com/uploader.php"
$txtpath="C:\Users\masod\Desktop\tt.txt"
Invoke-RestMethod -Uri $uri -Method  post  -InFile $txtpath

My php code:

<?php
$file_name = $_FILES['UploadedFile']['name'];
$target_path = "uploads/".$file_name;
if(move_uploaded_file($_FILES['UploadedFile']['tmp_name'], $target_path)) {
echo "ok";}
else {
echo "no ok";}
?>
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • this is my php code –  Oct 17 '17 at 15:43
  • Have you tried https://stackoverflow.com/questions/38164723/uploading-file-to-http-via-powershell and https://stackoverflow.com/questions/24672760/powershells-invoke-restmethod-equivalent-of-curl-u-basic-authentication ? – ZerosAndOnes Oct 17 '17 at 15:50
  • excuse me It did not help me. Could my code be damned? –  Oct 17 '17 at 17:26
  • It could be, however, I am not experienced in using powershell for uploading files. So I might be wrong. – ZerosAndOnes Oct 18 '17 at 05:46
  • It is ridiculous There is no one to answer my question –  Oct 18 '17 at 08:04
  • Would be great if you further elaborated on the obstacles you mention. Please provide them. Especially if you get an exception. This would make it easier to supply an answer. – Lars Bingchong Oct 18 '17 at 08:40
  • It's too banal Just look at the my code. You will understand the routine. I want to upload a file from my system to the host using a http. PowerShell will simplify my work. Actually, everything is true and not encountered error, but the upload does not happen –  Oct 18 '17 at 08:59

0 Answers0