Pages

Monday, September 1, 2014

Download files through Command Prompt in Windows

HTTP
PowerShell

$source = "http://yoursite.com/file.xml"
$destination = "c:\application\data\newdata.xml"
Invoke-WebRequest $source -OutFile $destination

The Invoke-WebRequest cmdlet
Invoke-WebRequest is a cmdlet that lets you upload or download data from a remote server. This cmdlet allows for user agents, proxies, and credentials.

FTP
PowerShell

$source = "ftp://yoursite.com/file.xml"
$destination = "c:\application\data\newdata.xml"

Invoke-WebRequest $source -OutFile $destination -Credential ftpUser

The code example above is almost identical to the HTTP sample, with the main difference being that the $source variable has “ftp” at the beginning instead of “http”. You may also notice that we have used the -Credential parameter since FTP connections generally require a username and password.

No comments:

Post a Comment