Pequeño script para subir un archivo, borrarlo o descargarlo usando curl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- #!/bin/bash
- # fanta <fanta@56k.es> 03/May/2022
- # Script sencillo para subir un archivo a un server ftp
- # Permite tambien borrar un archivo y descargarlo
- # Ejemplos:
- #
- # Upload a file example: curlFTP -u /var/backups/vzdump-qemu-109-2022_05_03-01_47_35.vma.lzo
- # Remove remote file example: curlFTP -r vzdump-qemu-109-2022_05_03-01_47_35.vma.lzo
- # Download a file example: curlFTP -d vzdump-qemu-109-2022_05_03-01_47_35.vma.lzo
-
- user=""
- passwd=""
- ftpHost=""
- mode="$1" # -d -u -r
- file="$2"
-
- function main(){
- checkCurl
- checkFTP
- checkMode
- }
-
- function checkCurl(){
- [ -z "$(whereis -b curl | awk {'print$2'})" ] && echo "curl - Maybe it is not installed on the system. Sorry but I can't continue." && exit
- }
-
- function checkFTP(){
- ftpProtocol=$(curl -V | grep -i "Protocols" | tr " " "\n" | grep -w ftp)
- if [ $ftpProtocol != "ftp" ]; then echo "Please compile curl with ftp protocol support"; exit; fi
- }
-
- function checkMode(){
- [ -z "$mode" ] && echo -e "Please specifies an option: -d -u -r\n -d download a file\n -u upload a file\n -r remove a file" && exit
- if [ $mode == "-u" ] ; then checkFile; fi
- if [ $mode == "-u" ] ; then uploadFile ; fi
- if [ $mode == "-r" ] ; then removeRemoteFile ; fi
- if [ $mode == "-d" ] ; then downloadFile ; fi
- }
-
- function checkFile(){
- [ -z "$file" ] && echo -e "Please specifies a filename." && exit
- if [ -f "$file" ]; then echo "File: $file"; else echo "i can't find the file [ $file ] in that path"; exit; fi
- }
-
- function uploadFile(){
- curl -T "$file" ftp://"$user":"$passwd"@"$ftpHost"/
- }
-
- function downloadFile(){
- curl --output $file ftp://"$user":"$passwd"@"$ftpHost"/"$file"
- }
-
- function removeRemoteFile(){
- curl -u "$user:$passwd" --quote "DELE $file" ftp://"$ftpHost"
- }
-
- main
|