Skip to content

AjdinMasic-code/SFTP-Transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

SFTP-Transfer

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

I will be updating this repository with more SFTP scripts like handling multiple files, directories, etc.

About

A template for file transfers via SFTP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages