SCP multiple files from remote with 1 password entered

wallis

New Member
Joined
May 15, 2024
Messages
10
Reaction score
3
Credits
120
The following works, but I have to enter a password twice, once for each file to be copied
scp [email protected]:/home/pi{test1.py,test2.py} /home/walli

I tried the following from searching the Internet:
scp [email protected]:\{test1.py,test2.py\} /home/walli
The error is: scp: {test1.py,test2.py}: No such file or directory when the password is entered.

This next line also gives an error:
scp [email protected]:/home/pi/\{test1.py,test2.py\} /home/walli
The error is: scp: /home/pi/{test1.py,test2.py}: No such file or directory

Does anyone know how to copy multiple files and only require the password to be entered once?
Thanks,
Wallis
 


The following works, but I have to enter a password twice, once for each file to be copied
scp [email protected]:/home/pi{test1.py,test2.py} /home/walli

I tried the following from searching the Internet:
scp [email protected]:\{test1.py,test2.py\} /home/walli
The error is: scp: {test1.py,test2.py}: No such file or directory when the password is entered.

This next line also gives an error:
scp [email protected]:/home/pi/\{test1.py,test2.py\} /home/walli
The error is: scp: /home/pi/{test1.py,test2.py}: No such file or directory

Does anyone know how to copy multiple files and only require the password to be entered once?
Thanks,
Wallis
If the scp command is to include all the files with .py as a suffix, then the following will normally require just a single password:
Code:
scp [email protected]:/home/pi/*.py /home/walli

If there are some files with the .py suffix that are not to be copied, then some other common element in the names of the files-to-be-copied may be selected, e.g. to copy just the .py files with "test" in their names:
Code:
$ ls
test1.py test2.py old.py older.py

scp [email protected]:/home/pi/test*.py /home/walli
 
The files will not always be .py files and even when they are all .py files, not all .py files should be copied and there is no other common way to identify them excep thru their full names.
 
scp myfile1 sometext.txt shellscript.sh [email protected]:/directory

This only asks for one password. If you put the files in expansion braces it would be
considered to be multiple commands.

This would work also.
Code:
for file in test1.py test2.py anotherfile.txt yetanotherfile.md; do
  scp [email protected]:/home/pi/$file /home/walli
done
 
Last edited:
to dos2unix,
I can copy multiples files from a local machine to a remote machine without any issue, my issue is in receiving multiple files from a remote to the local machine with just one password prompt.

I do not understand you first answer of
scp myfile1 sometext.txt shellscript.sh [email protected]:/directory

It does does not copy files from the remote at 192.168.1.201 to the local machine.
the remote IP address is not specified in the command.
I do not understand the purpose of shellscript.sh in the command

Your second answer with the for...done loop works great, but requires a password to be entered for each file to be received to the local machine.

Thanks for your response
 
I do not understand you first answer of
scp myfile1 sometext.txt shellscript.sh [email protected]:/directory

It does does not copy files from the remote at 192.168.1.201 to the local machine.

Then something is wrong, I assure you we do this quite frequently, dozens of times a day.
Can you paste the exact command you are using?

Your second answer with the for...done loop works great, but requires a password to be entered for each file to be received to the local machine

Yes, I was showing you, that it is the equivalent of putting your files between expansion brackets.
 
I believe you can use a program called ssh-agent to store your password for your private key in memory so you won't have to type a password every time before using it. You can use ~/.ssh/ to store config information about specific hosts, like what key to use, but I don't know if that will let you store the password for a remote host.

Signed,

Matthew Campbell
 
Thanks for you patience:
My remote is at 192.168.1.201 in home/pi where testa.py and testb.py exist.
I am trying to copy testa.py and testb.py from the remote at 192.168.1.201:/home/pi to
the local at 192.168.1.62:/home/walli and only enter the password one time.

Here is what I tried:
scp testa.py testb.py shellscript.sh [email protected]:/home/pi
[email protected]'s password: xxxxxxx
scp: stat local "testa.py": No such file or directory

To copy one file from remote to local, I use:
scp [email protected]:/home/pi/testa.py /home/walli
and I don't how you how your example does this since the remote information has to come before the local information.
I am and old 83 year old retired IT guy trying to learn how to use bash scripts with scp, please bear with me.

Would you please give me your answer as an example where I want to copy testa.py and testb.py at /home/pi on the remote at 192.168.1.201 to the local machine @192.168.1.62:/home/walli and only require the password one time.

Thanks Again
And thanks Matthew, I will try your suggestion to store the passwords.
 
I can copy multiples files from a local machine to a remote machine without any issue, my issue is in receiving multiple files from a remote to the local machine with just one password prompt.

Ok, that's little different
In that case, you would need to enter the password three times, or use the ssh-keys mentioned above.
The other option is to setup a sftp server.
 
I will try both the ssh-keys and sftp and thanks much for your help and the others

Wallis
 
If you do decide to set up an sftp server then make sure it's a safe version. There was a version that had a buffer overflow vulnerability that allowed bad guys to hack in using the login prompt. I don't believe regular ftp had that problem, especially if you use -A to only allow anonymous logins.

Signed,

Matthew Campbell
 


Members online


Latest posts

Top