I’m supporting an environment which excluded PowerShell and most other software. When the system required FTP file transfers, we used the Windows command line FTP client with automation scripting. It was functional although clumsy. PowerShell has potential for more graceful FTP, but faces a more restrictive environment. Without delving into the details, these sites were useful references (or near-verbatim sources) to generate the scripts below:
cmd-ftp-with-powershell.cmd
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -File "C:\Users\weberg.e\Documents\ProductionEngineering\VbaSourceStorage\ftp-get.ps1"
ftp-get.ps1
# Reference: https://www.thomasmaurer.ch/2010/11/powershell-ftp-upload-and-download/ param ($remotefile, $localfile, $username, $password) Start-Transcript -Path "C:\Users\weberg.e\Documents\ProductionEngineering\VbaSourceStorage\ftp-get.ps1.log" # Config # $Username = "FTPUSER" # $Password = "P@assw0rd" # $LocalFile = "C:\Temp\file.zip" # $RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip" if($username -eq "") { $username = Read-Host -Prompt 'Type your user name' } if($password -eq "") { $password = Read-Host -Prompt 'Type your password' } # $LocalFile = "C:\Users\weberg.e\Documents\ProductionEngineering\VbaSourceStorage\Documents\VibeTestReport.dotm" # $RemoteFile = "ftp://internal-server/TstSysCfgs/EnvTst/Vibe/VibeTestReport.dotm" # Create a FTPWebRequest $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile) $FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password) $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile $FTPRequest.UseBinary = $true $FTPRequest.KeepAlive = $false # Send the ftp request $FTPResponse = $FTPRequest.GetResponse() # Get a download stream from the server response $ResponseStream = $FTPResponse.GetResponseStream() # Create the target file on the local system and the download buffer $LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create) [byte[]]$ReadBuffer = New-Object byte[] 1024 # Loop through the download do { $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024) $LocalFileFile.Write($ReadBuffer,0,$ReadLength) } while ($ReadLength -ne 0) Stop-Transcript
ftp-put.ps1
# Reference: https://www.thomasmaurer.ch/2010/11/powershell-ftp-upload-and-download/
param ($remotefile, $localfile, $username, $password)
# Config
# $Username = "FTPUSER"
# $Password = "P@assw0rd"
# $LocalFile = "C:\Temp\file.zip"
# $RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip"
if($username -eq "") { $username = Read-Host -Prompt 'Type your user name' }
if($password -eq "") { $password = Read-Host -Prompt 'Type your password' }
# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = gc -en byte $LocalFile
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup
$Run.Close()
$Run.Dispose()
Also, permitting trusted access to the Office object models, working with the object models, masking password input, standard parameterization and providing Help within PowerShell:
Office info:
https://www.google.com/search?q=word+document+object+vba+model
https://docs.microsoft.com/en-us/office/vba/api/overview/word/object-model
https://docs.microsoft.com/en-us/office/vba/api/word.document
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook
https://docs.microsoft.com/en-us/office/vba/api/word(enumerations)
https://word.tips.net/T001622_Words_Object_Model.html
A short VBscript that will extract comments from a Word document: https://gist.github.com/matt-bernhardt/c05d86b7ddaf206e1ef292e84cf2fd88
Powershell info: