Solved

Curl and Powershell

Posted on 2014-03-06
6
2,805 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
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 334 total points
Comment Utility
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 10

Expert Comment

by:JoeKlimis
Comment Utility
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 68

Assisted Solution

by:Qlemo
Qlemo earned 166 total points
Comment Utility
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
Comment Utility
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 10

Assisted Solution

by:JoeKlimis
JoeKlimis earned 334 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now