Solved

Curl and Powershell

Posted on 2014-03-06
6
2,918 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
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 10

Expert Comment

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

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 10

Assisted Solution

by:JoeKlimis
JoeKlimis 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

911 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

21 Experts available now in Live!

Get 1:1 Help Now