Ssh – file transfer with ssh pipe; without scp

file-transferpipescpssh

Scenario: I'm having about hundred odd text files which are compressed as .gz. They need to be transferred to a remote server. I do not want to use scp. Both, linux servers.

my requirement/my idea: I want to write and execute a bash script on source server for this. What I want is like zcat each of the files, pipe that output over ssh user@remote(its already configured passwordless), then have those outputs redirected into a text file on the remote server. Is this way correct? If so how to implement this?

Thanks,

Best Answer

You can simply do it like this:

for file in $(ls dir/); do zcat ${file} | ssh user@remote "cat > /path/${file}"; done