Solved

Curl and Powershell

Posted on 2014-03-06
6
3,261 Views
Last Modified: 2014-03-09
I am using curl to upload a file to an sftp server on windows.

curl -k - t file - user password sftp server

I can run this from the command line, can i call this from power shell and is there a way to test if the curl command was successful in file upload?

Thanks
0
Comment
Question by:Robbie_Doherty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
Joe Klimis earned 334 total points
ID: 39910390
Hi

you can capture the status return like this
            $Command = ".\curl.exe 'https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + $ScreenName + "&count=150&max_id=" + $FinalID + "' --insecure"
            [xml]$Res = invoke-expression $Command

See this article url-for-powershell-finally-i-can-get-some-rest

alternatively  see Powershell v3 s it may be you can do this natively

I hope this helps

Joe
0
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 39912583
Hi Robbie_Doherty

Please confirm that you are trying to upload a file via sftp from windows , and I can construct the command you require , if you are unable to work it out from above

if the command returns anything other than 0 there has been a problem, these codes can be look up from the bottom of the Curl manual
I am unsure which version of Curl you are using this one includes aManual and download

Regards

Joe
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 166 total points
ID: 39912585
You can usually use the same command as in cmd.exe. You'll only need to take care of spaces, quotes and other special characters in it.
You can assign the result (if any) to a variable.
You can ask for the success state, if the command allows for that, by asking for $? (which is $true on success, else $false).
Putting that together:
$result = curl -k - t file - user password sftp server
if (!$?) { write-host "Curl call not successful: $result" }

Open in new window

0
 

Author Comment

by:Robbie_Doherty
ID: 39912741
Hi

Yes I am trying to upload sftp from windows, I have installed cURL for windows and can run commands from the cmd line, but cannot run it in power shell.

have tried \curl.exe before the command,

thanks
0
 
LVL 11

Assisted Solution

by:Joe Klimis
Joe Klimis earned 334 total points
ID: 39913693
Hi Robbie

the problem may be you need to specifiy the path unless put the curl folder in the search path  for me

:\Users\JoeK\Downloads\curl-7.35.0-win64\curl-7.35.0-win64\bin\curl.exe --help

works 

and 

Curl --help does not

Open in new window


give this a go

Joe
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question