Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
sftpput.zsh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2## ------------------------------------------------------------------------------------------
3##
4## Utils to get and upload files on sftp
5##
6## ------------------------------------------------------------------------------------------
7
8#!/bin/zsh
9script=${0##*/}
10
11source ${0%${script}}ulib.sh
12
13if do_usage $*; then
14 usage "$script file_path/filename sftp_path"\
15 "\nUtility script to upload files on sftp, for example, \"$script data.root user/tmp\""
16fi
17
18case $# in
19 2) ;;
20 *) fatal "Wrong number of arguments."
21esac
22
23notice `which ${script:r}` ${1} ${2}
24
25FILENAME=${1}
26SFTPPATH=${2}
27wget -q sftp.km3net.de/${SFTPPATH}/${FILENAME:t} -O ${FILENAME:t}_tmp
28
29if [ -s ${FILENAME:t}_tmp ]; then
30 rm ${FILENAME:t}_tmp
31 fatal "File ${FILENAME:t} is already on sftp server, quitting."
32fi
33rm ${FILENAME:t}_tmp
34
35if [ -f ${FILENAME} ]; then
36 md5sum ${FILENAME} > ${FILENAME:t}.md5
37 echo "Enter KM3NeT SFTP password"
38 lftp sftp://km3net@sftp.km3net.de -e "mkdir $SFTPPATH; cd $SFTPPATH; put $FILENAME ${FILENAME:t}.md5; bye"
39 rm ${FILENAME:t}.md5
40 echo "Checking the uploaded file"
41 mkdir _sftpgettmp
42 cd _sftpgettmp
43 sftpget $SFTPPATH/${FILENAME:t}
44 cd ../
45 rm -rf _sftpgettmp
46else
47 fatal "File ${FILENAME} not found locally"
48fi