Solved

Curl and Powershell

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

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 10

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 69

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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