Bulk copy files over sftp with a delay between each file

Viewed 32

I want to move my files from one directory to SFTP and further to another directory in sequence not together.

Let's say if my directories are A and B.

Here is my code:

#!/bin/bash
cp -R /usr/sap/tmp/Dir A/. /usr/sap/tmp/Dir B/
lftp <<_EOF_
open sftp://User:Password@Host -p Port
lcd /usr/sap/tmp/Dir A
cd /
pwd
mput -E /usr/sap/tmp/Dir A/*.dat
exit
_EOF_

This works fine. But the only problem is it moves all files together at the same time from dir A to SFTP. How can I get it to move files one by one (in sequence, say the files moved to SFTP should have at least difference of one second between them)?

1 Answers

First create a file with commands for all files.

cat <<@ > inputfile
open sftp://User:Password@Host -p Port
lcd /usr/sap/tmp/Dir A
cd /
pwd
@

find . -type f -name sa\*.txt -print0 |
  xargs -n1 --null -I'{}' printf "%s\n" "mput '{}'" '!'"sleep 1" >> inputfile
echo "exit" >> inputfile

Next stream that file

lftp << inputfile
Related