Skip to content

Commit 2c88ff4

Browse files
kowalskkowalsk
authored andcommitted
New full version that works
Inner file is run as many times as there are files by the outer file. This is because Inner file can only rename one file at a time on SFTP due to limitations of SFTP protocol
1 parent 62663e6 commit 2c88ff4

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

SFTPscript.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

inner.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
#This script uploads one file at a time to SFTP server
4+
#It renames local file first to .tmp
5+
#It then connects, uploads file, renames it back to no .tmp
6+
#It then disconnects and delets the local .tmp file
7+
8+
9+
#keeping original name for later step
10+
filename=$(basename $1 .tmp)
11+
12+
#renaming original local file to FILENAME.tmp to mark it is being processed
13+
mv $1 $1.tmp
14+
15+
16+
#connecting to SFTP using username & ssh keys - not passwords
17+
sftp USERNAME@IP_ADDRESS << EOT
18+
cd out
19+
put $1.tmp
20+
rename $filename.tmp $filename
21+
ls -al
22+
bye
23+
EOT
24+
25+
#removing the original file
26+
rm $1.tmp

outer.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# this script just runs the "inner.sh" script as many times as there are files in the directory
4+
for file in ftpsource/*.csv; do
5+
./inner.sh $file
6+
done

0 commit comments

Comments
 (0)