I need help writing a simple SFTP shell script to transfer a few files. What I have is server info of the remote computer I will be sending the files to. Please help I am new to the shell/linux stuff.
Example: Password: 1234
User: We1234
We12345@hostname.com
Name of files I want to transfer: RED*
Where I want to drop the files: FOLDER_2017
You have to set up ssh keys on both the local and the remote boxes FIRST.
Then you can use passwordless file transmission.
Debian example, works almost anywhere:
How to set up ssh so you aren't asked for a password
1 Like
Hello Yanisol,
Below a little script which should do the work:
#!/bin/bash
user_sftp="We1234"
pass_sftp="1234"
server_sftp="We12345@hostname.com"
cd /file2transfert/
sshpass -p $pass_sftp sftp $user_sftp@$server_sftp << !
cd FOLDER_2017/
mput RED*
exit
!
Hoping have helped:)
Thanks for making a suggestion Arnaudh78, but this would leave a few security issues:-
- The credentials are plaintext in the script
- The credentials will be plaintext during the execution of sshpass
I would strongly recommend using the suggestion of jim mcnamara which keeps your credentials more secure. Of course, you have to ensure that no-one steals your private key, but that is a requirement of the set up anyway.
Kind regards,
Robin