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.
MIHIR KAR#Hadoop #Oracle_DB #UNIX beginnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Use mput rather than put.
omarfaridCommented:
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!"
nociSoftware EngineerCommented:
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

serialbandCommented:
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/
kenfcampCommented:
sftp uses ssh links underneath, so scp should also work

Or RSYNC over SSH for that matter

To recreate source directory and transfer contents - (source directory created)
rsync -avz -P --stats source-folder this-user@some-domain.com:/path/to/destination-folder/

Open in new window


To transfer contents of source directory - (source directory not created)
rsync -avz -P --stats source-folder/ this-user@some-domain.com:/path/to/destination-folder/

Open in new window


adding "--delete" before source folder will delete files that are not in subsequent transfers or are older than what's being transferred.
Be careful with this, if you're in the wrong location you could delete important files

If the files are the same, they are skipped

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.