How to upload http file via powershell

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

My powershell code ;

$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";}
?>
Parents
  • I am not sure what the question is here.
    Are you saying, what you show is not working?
    Are you asking how to combine your PoSH samp[le with your PhP sample?
    Are looking to do this with only PoSH and just showing how you would do this in PERL?

    There are scritps on the MS PowerShell Gallery as well as MSDN, TechNet and the O365 blogs, this show how to do this, which you can download and modify to your needs.

    For example, well, this is FTP, but I think you'll get the idea.
    'gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c'

    This is to ShoarePoint in O365.
    'blogs.technet.microsoft.com/fromthefield/2014/02/19/office-365-powershell-script-to-upload-files-to-a-document-library-using-csom/'

    This is uploading with PoSH using BITS.
    'msdn.microsoft.com/en-us/library/windows/desktop/ee663885(v=vs.85).aspx'

    Then there is the Web client upload .Net method.
    'msdn.microsoft.com/en-us/library/system.net.webclient.uploadfile(v=vs.110).aspx'

    So, you do have options, but again, I am not sure of the question here.
Reply
  • I am not sure what the question is here.
    Are you saying, what you show is not working?
    Are you asking how to combine your PoSH samp[le with your PhP sample?
    Are looking to do this with only PoSH and just showing how you would do this in PERL?

    There are scritps on the MS PowerShell Gallery as well as MSDN, TechNet and the O365 blogs, this show how to do this, which you can download and modify to your needs.

    For example, well, this is FTP, but I think you'll get the idea.
    'gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c'

    This is to ShoarePoint in O365.
    'blogs.technet.microsoft.com/fromthefield/2014/02/19/office-365-powershell-script-to-upload-files-to-a-document-library-using-csom/'

    This is uploading with PoSH using BITS.
    'msdn.microsoft.com/en-us/library/windows/desktop/ee663885(v=vs.85).aspx'

    Then there is the Web client upload .Net method.
    'msdn.microsoft.com/en-us/library/system.net.webclient.uploadfile(v=vs.110).aspx'

    So, you do have options, but again, I am not sure of the question here.
Children
No Data