- 1 year ago
Include password in SFTP batch file
Including passwords in plain text is generally not recommended for security reasons. However, if you still need to include a password in an SFTP batch file, you can make use of the -b
option to pass the SFTP commands via a separate file, and then use variables or command-line arguments to supply the password.
Here's an example of how you can achieve this:
Create a separate text file (e.g.,
sftp_commands.txt
) to store the SFTP commands:arduinoput local_file remote_file
quit
Create a batch file (e.g.,
sftp_batch.bat
) to execute the SFTP commands using thesftp
command-line tool:bat@echo off
set SFTP_HOST=example.com
set SFTP_USER=username
set SFTP_PASSWORD=your_password
echo open %SFTP_HOST%> sftp_script.txt
echo %SFTP_USER%>> sftp_script.txt
echo %SFTP_PASSWORD%>> sftp_script.txt
echo put local_file remote_file>> sftp_script.txt
echo quit>> sftp_script.txt
sftp -b sftp_script.txt
del sftp_script.txt
In this example,
%SFTP_HOST%
,%SFTP_USER%
, and%SFTP_PASSWORD%
are placeholders for the actual host, username, and password.Run the batch file (
sftp_batch.bat
) to execute the SFTP commands.
By storing the password in a variable within the batch file, you can avoid directly exposing the password in plain text. However, please note that this method is still not entirely secure, and it's recommended to use more secure methods such as public/private key authentication or secure credential storage systems when dealing with sensitive information like passwords.