Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Curl and Powershell

Posted on 2014-03-06
6
Medium Priority
?
3,795 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 11

Accepted Solution

by:
Joe Klimis earned 1002 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 71

Assisted Solution

by:Qlemo
Qlemo earned 498 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 1002 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
This article is about my experience upgrading my consulting machine to Windows 10 Version 1709 (The Fall 2017 Creator Update)
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

927 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