This PowerShell script (sftp_download.ps1
) is designed to automate file downloads from an SFTP server, handle log rotation, and create backup copies. It is ideal for workflows requiring regular and secure management of remote files.
- Automated connection to an SFTP server using secure credentials.
- Download files from a specified remote directory.
- Automatic backup of downloaded files.
- Daily log rotation and compression.
- Error handling throughout the download and backup process.
- PowerShell: The script is written and tested using PowerShell 5.1.
- Posh-SSH Module: Ensure the Posh-SSH module is installed, which is used to handle the SFTP connection.
- Encrypted Credentials: The script requires credentials to be stored in encrypted XML files using
Export-CliXml
.
Install-Module -Name Posh-SSH -Scope CurrentUser -Force
Before running the script, make sure to configure the following parameters:
- SFTP Configuration: Set the host, port, and remote path for file downloads.
- Network Drive Configuration: Configure the local network drive for backing up the downloaded files.
- Credentials: Save the required credentials in encrypted XML files for SFTP access and network drive.
Run the following commands to create the credential files:
$username = "your_username"
$password = ConvertTo-SecureString "your_password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)
# Save the SFTP credentials
$credential | Export-CliXml -Path "C:\script\sftp_download\sftp_credentials.xml"
# Save the network drive credentials
$credential | Export-CliXml -Path "C:\script\sftp_download\netdrive_credentials.xml"
-
Clone the Repository
Clone the repository from your GitHub account:
git clone https://github.com/Stufo76/Sftp-Download.git
-
Run the Script
To run the script, open PowerShell as an administrator and execute the following command:
.\sftp_download.ps1
This project is licensed under the GPL-3.0 License. For more details, refer to the LICENSE.
- Diego Pastore
- GitHub: Stufo76
- Email: [email protected]
- Ensure the
Posh-SSH
module is installed and loaded correctly. - The credential files are encrypted and can only be used by the user who created them.
- It is recommended to run this script in a secure environment, as operations involving remote files and credentials are sensitive.
If you have suggestions, issues, or questions, feel free to open an Issue or make a Pull Request. Thank you for using this script!