Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SFTP - File transfer completed successfully

Status
Not open for further replies.

HHG

Technical User
Nov 8, 2003
68
GB
Hi

I am on solaris v10 using bash as well.

I have generated a script that transfers files using sftp but I some how need to know that all the files have transferred i.e. transfer has completed successfully.

The last file that will get sent will be EOF{todaysdate)(followedbythenumber of files sent) e.g. EOF021007127

Any offer of help would be greatly appreciated.
 
A starting point:
> EOF$(date +%d%m%y)${NbFiles}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes that is the naming convention of the file that will be sent last. I need to know how that file has been transferred successfully.

I need to check that all the files have transferred.

e.g.

put file
put EOFfile
check EOFfile exists
maybe get this file and check it exists before I close the connection.
 

Try:
Code:
ftp ...<<!EOF >ftp.log
...etc...
put file
put EOFfile
#check EOFfile exists
ls -l
bye
!EOF
# Then examine the ftp log file:
cat ftp.log|grep EOF
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hi Thanks for this, but my script does the following

does an ls and saves file names into a file.
then does a for i statment using basename $1 - I create a ftpscript file that looks like this:-

put abc
put def
put ghi
put EOF031007127
quit

then I use sftp -C -b ftpscript to host/ipaddress

I need a check after it does the put EOF031007127 and before it quit sftp. Any ideas please will help.

 

Except for the ls or dir command, there is no way to check if a remote file exists, and there are no conditional (if's) commands in sftp.

Try something like this:
Code:
cat - <<! >ftpscript
put abc
put def
put ghi
put EOF031007127
ls -l
quit
!
sftp -C -b ftpscript to host/ipaddress >ftp.log
is_ok=$(grep 'EOF031007127' ftp.log|wc -l)
if [ is_ok -eq 1 ]
then
  echo "File transfer completed ok."
else
  echo "File transfer failed."
fi
[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

PS: Change "if [ is_ok -eq 1 ]" to "if [ $is_ok -eq 1 ]"




----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

PS2: Actually it's "if [ $is_ok -eq 3 ]"


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hi LKBrwnDBA
Thanks for this. For the grep command is it possible to do a wild card on the EOF at the later part of the file name will always be different like this. just looked at the man on grep but doesn't referr to wildcard matches on file name.

i.e. is_ok=$(grep 'EOF*' ftp.log|wc -l)
 

Yes, but better supply the full name like:

eofFile="EOF$(date +%d%m%y)${NbFiles}"
#...etc...
is_ok=$(grep $eofFile ftp.log|wc -l)

[thumbsup2]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Yes I actually figured it out.

I created a variable and save the whole file name in it.

But for some reason when I run the script the script falls over with the following error:-
Generating ftp script
./transfer.sh[25]: syntax error at line 28 : `<<' unmatched

This bit of the script look like this.

echo "Starting ftp upload.."
/usr/bin/sftp -C -b $HOME_DIR/ftpscript $TARGET_HOST <<! > $HOME_DIR/ftp.log
EOT=$(grep $EOT_TEST ftp.log|wc -l)
if [$EOT = 1]
then
#Write message file to log file
date
echo "File Transfer Completed Successfully"
else
#Write message file to log file
date
echo "Transfer failed "
fi

Any idea please. thanks - cam not wait to finish this bit.
 
/usr/bin/sftp -C -b $HOME_DIR/ftpscript $TARGET_HOST > $HOME_DIR/ftp.log

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think one of the problems is that I am using ping in the bash-3 shell which can not be done. I have a command like this in my script:-
IPFUP=$(ping ipaddress|awk '{print $3}')
if [$IPFUP = "alive"]
etc....

does anyone now what is the equivalent to ping using bash-3 in my script I have a test to see if the ip address is alive.
any help will be great help. Cheers.
 
I am using ping in the bash-3 shell which can not be done
Really ?
man ping

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Is it absolutely necessary to use SFTP, or can you use SCP and SSH instead?

Or even just ssh itself, with a remote execution statement something like..

DIDMYFILEGO=`ssh -n userid@remotehost -c "ls ${EXPECTEDFILE} | wc -l"`
 
Hi Chapter11

Thanks for this. I managed to get it working in bash-3, I simple put in the full path to ping and it worked fine.

However, a further quick question.

Do you know if solaris v10 can copes with ftps if so do you know how to setup/syntax. Any advice will be very much appreciated. Thanks


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top