A template for file transfers via SFTP
Requirements:
Posh-SSH
Powershell Version 3+
Parameters to pass:
sftpUpload.ps1
[-logFile ]
[-sourceFile ]
[-sftpServer ]
[-sftpDest ]
[-username ]
[-password ]
How to use:
.\sftpUpload.ps1 -logFile "C:\LogFile_$(Get-Date -UFormat %Y%m%d%H%M).txt" -sourceFile "C:\bla.txt" -sftpServer "server.bla.com" -sftpDest "/foo/bar" -username "username" -password (ConvertTo-SecureString "password" -AsPlainText -Force)
Notes:
Password is passed as secure string for security purposes. You can, but I don't recommend, change how the Param is set up.
I.E.
Param(
[string]$logFile,
[string]$sourceFile,
[string]$sftpServer,
[string]$sftpDest,
[string]$username,
[SecureString]$password
)
TO:
Param(
[string]$logFile,
[string]$sourceFile,
[string]$sftpServer,
[string]$sftpDest,
[string]$username,
[string]$password
)
After the above code block:
$password = ConvertTo-SecureString "$password" -AsPlainText -Force)
That way you can avoid converting the password to SecureString when passing the parameter to the script. Again I don't recommend doing this for security reasons
AjdinMasic-code/SFTP-Transfer
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|