Skip to content

Commit

Permalink
New full version that works
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kowalsk authored and kowalsk committed Jan 15, 2016
1 parent 62663e6 commit 2c88ff4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
18 changes: 0 additions & 18 deletions SFTPscript.sh

This file was deleted.

26 changes: 26 additions & 0 deletions inner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

#This script uploads one file at a time to SFTP server
#It renames local file first to .tmp
#It then connects, uploads file, renames it back to no .tmp
#It then disconnects and delets the local .tmp file


#keeping original name for later step
filename=$(basename $1 .tmp)

#renaming original local file to FILENAME.tmp to mark it is being processed
mv $1 $1.tmp


#connecting to SFTP using username & ssh keys - not passwords
sftp USERNAME@IP_ADDRESS << EOT
cd out
put $1.tmp
rename $filename.tmp $filename
ls -al
bye
EOT

#removing the original file
rm $1.tmp
6 changes: 6 additions & 0 deletions outer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# this script just runs the "inner.sh" script as many times as there are files in the directory
for file in ftpsource/*.csv; do
./inner.sh $file
done

0 comments on commit 2c88ff4

Please sign in to comment.