Skip to content

Instantly share code, notes, and snippets.

@jeevan-vj
Forked from chardcastle/deploy-static.ps1
Created December 3, 2017 14:39
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 jeevan-vj/0019bf35e1c0a586be8f0e469bda34c8 to your computer and use it in GitHub Desktop.
Save jeevan-vj/0019bf35e1c0a586be8f0e469bda34c8 to your computer and use it in GitHub Desktop.
Upload files (recursive) via powershell
## Automate FTP uploads
## Go to destination
cd C:\Test
$location = Get-Location
"We are here: $location"
## Get files
$files = Get-ChildItem -recurse
## Get ftp object
$ftp_client = New-Object System.Net.WebClient
$ftp_address = "ftp://user:pass@adress:/home/chardcastle/test"
## Make uploads
foreach($file in $files)
{
$directory = "";
$source = $file.DirectoryName + "\" + $file;
if ($File.DirectoryName.Length -gt 0)
{
$directory = $file.DirectoryName.Replace($Location,"")
}
$Directory += "/";
$FtpCommand = $ftp_address + $directory + $file
$uri = New-Object System.Uri($ftp_command)
"Command is " + $uri + " file is $source"
$ftp_client.UploadFile($uri, $source)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment