The goal is for an SSMS job to transfer a single file from an SFTP to a local drive. It will work off a server so it should have little-to-no 3rd party requirements.
PowerShell 5 has native FTP functionality so I want to work with that. This should be simple but I'm finding very little documentation or working examples on Google. The example below is derived from this SO post. When run, 'The URI prefix is not recognized' error is returned.
$source = 'ftp.companyname.com:/remotetestfolder/TestBlankFile.xlsx'
$target = 'C:\Users\....\...\Desktop\TestBlankFile2.xlsx'
$Username = 'myusername'
$password = Microsoft.PowerShell.Security\ConvertTo-SecureString -String 'mypassword' -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $password
# Download
Invoke-WebRequest -Uri $source -OutFile $target -Credential $credential -UseBasicParsing
Should I create separate variables for the remote directory and filename? Where do they go in?
Update: Right now, I manually retrieve files using the steps below. My goal is to automate these steps (preferably with only native Windows commands and processes)
- Open Filezilla.
- If a connection isn't already saved, create a connection to SFTP.companyname.com, add my username & password, and whatever other changes are needed.
- Click to connect to the FTP and then download the files I need.