Skip to content

Instantly share code, notes, and snippets.

@micmaher
Created March 28, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmaher/4320c09722af5c53cd0c to your computer and use it in GitHub Desktop.
Save micmaher/4320c09722af5c53cd0c to your computer and use it in GitHub Desktop.
FTP Module for managing Foscam Recordings
#Requires -Modules PSFTP
Function Connect-Camera
{
<#
.SYNOPSIS
Connects to Security Camera to get video
.DESCRIPTION
Can wipe videos or download
.PARAMETER Delete
Remove all videos
.PARAMETER Download
Downloads all videos
.EXAMPLE
Connects to camera deletes all videos
Connect-Camera -delete
.EXAMPLE
Connects to camera and downloads videos to C:\Downloads
Connect-Camera -download C:\Downloads
.EXAMPLE
With not download location specified C:\temp is assumed
Connect-Camera -download
.NOTES
Michael Maher on 14/2/16
Requires FTP Module in place
.LINK
FTP Module available from https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb
#>
param(
[switch] $download,
[switch] $delete,
[string] $localDir = "c:\temp")
Import-Module PSFTP
$Camera = "VideoCamera"
$ftpServer = "ftp://192.168.1.1:50021"
$mediaFolder = "/IPCamera/"
$userName = "user"
$password = "password"
$SecureString = ConvertTo-SecureString $password -AsPlainText -Force
$PSCredential = New-Object System.Management.Automation.PSCredential ($userName, $SecureString)
Set-FTPConnection -Credentials $PSCredential -Server $ftpServer -Session $Camera -UseBinary
$Session = Get-FTPConnection -Session $Camera
if($download){
Get-FTPChildItem -Session $Session -Path $mediaFolder -Recurse | `
Get-FTPItem -Session $Session -LocalPath $localDir -RecreateFolders -Overwrite
}
if ($delete) {
Get-FTPChildItem -Session $Session -Path $mediaFolder -Recurse | `
Remove-FTPItem -Session $Session -Recurse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment