Avatar of MIHIR KAR
MIHIR KAR
Flag for India asked on

How to SFTP multiple file from source to dest in Linux?

Hi Expert,

I have a SFTP job which is failing while transfer file for source to dest using "put" command.  As put command only works for single file.

Here my requirement is i want to transfer all the files available in "source/dir1/dir2" and want to merge them into single file then wanna SFTP.

Note:The script should also need to check how many files are there in the source directory before merge them!

thanks in advance.
LinuxShell Scripting

Avatar of undefined
Last Comment
kenfcamp

8/22/2022 - Mon
David Favor

Use mput rather than put.
omarfarid

Hi,

Your question is not clear,

you want to merge all files into one file then transfer? Why?

Also, below is not clear:

"The script should also need to check how many files are there in the source directory before merge them!"
noci

if sftp is used how about:   (sftp uses ssh links underneath, so scp should also work).

scp /from/where/ever/* user@remote_system:/to/dest/

Open in new window

recursive with:
scp -r /from/where/ever/* user@remote_system:/to/dest/

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
serialband

You would tar the files up at the source first, then put it on the destination

tar -czf transferfile.tgz source/dir1/dir2
then you can put transferfile.tgz in the destination.

You probably should be using rsync for this instead, as that will allow you to continue after an interruption.  rsync -az source/dir1/dir2 destination/
ASKER CERTIFIED SOLUTION
kenfcamp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.