LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   using ssh command (https://www.linuxquestions.org/questions/linux-newbie-8/using-ssh-command-886888/)

visitnag 06-17-2011 09:15 AM

using ssh command
 
Hi,

How can I use ssh command to get a file automatically from a remote server? The following command is working fine...
ssh remote-server "cat /path/to/file" > myfile
but here I have to write the output file name again. Here I am facing one problem. If I have to download some files with comman names, example file1,file2,file3...,file10, I give file*, but this will cat all the files into one output file. I want to copy all the files separately into my server along with the time stamp. In general cp -p command do this in the same server.

Reuti 06-17-2011 09:21 AM

There are several approaches. Use scp:
Code:

$ scp "remote-server:/path/to/dir/*" .
or similar to the command you used with tar:
Code:

$ ssh remote-server "tar -cz *" | tar -xz

ssrameez 06-17-2011 10:24 AM

scp -pr remoteserver:<path> <target path> -- to pull files.
scp -pr <path> remoteserver:<remote path> -- to push files.

If you have password less authentication for ssh it will copy all files together without prompting for password.
If not, it will ask for password, for every file getting copied.

visitnag 06-20-2011 12:11 PM

Its working fine. Unlike ssh the scp -pr is showing the file download percentage. My remote server is password protected. I have kept the multiple scp commands in a shell to download different files, but one problem I am facing is it is asking password for every file to be downloaded. Cont I use a loop to take the password for every different file to be downloaded automatically?

Reuti 06-20-2011 12:17 PM

Quote:

Originally Posted by visitnag (Post 4390916)
My remote server is password protected. I have kept the multiple scp commands in a shell to download different files, but one problem I am facing is it is asking password for every file to be downloaded. Cont I use a loop to take the password for every different file to be downloaded automatically?

I would suggest to move to an ssh-key with passphrase and a running ssh-agent to answer the requests. It’s outlines here, you can skip the final agent-forwarding though in case you have just one remote server.


All times are GMT -5. The time now is 05:23 PM.