New version

This commit is contained in:
2026-08-01 10:20:12 +02:00
parent f4a7362c4d
commit e8a3f3cec9
5 changed files with 93 additions and 130 deletions
+4 -10
View File
@@ -31,22 +31,16 @@ This app has a widget that show IP address when turned on.
sudo apt install lftp
- Configure the script [phone_synch.sh](./phone_synch.sh) (doc is embedded on the first lines).
- Configure the script [config.sh](./config.sh) to set FTP credentials and sync folders for phone and card.
Synchronize
-----------
At home, connect your mobile and computer to the wifi.
Start the mobile FPT server, using the widget
Start the mobile FTP server, using the widget
Launch the script :
./synch_phone.sh
Have also a memory card on your phone?
--------------------------------------
No problemo :)
Configure also the script [card_synch.sh](./card_synch.sh) and to launch both synchronisation, run:
./run.sh
This will synchronize both phone and card data according to the configuration in [config.sh](./config.sh).
-59
View File
@@ -1,59 +0,0 @@
#!/bin/bash
set -e # Exit if error
# This script synchronizes data from FTP into local folder:
# - remove file that do not exist anymore in the FTP (mirror -e)
#
# No modification will be done in the FTP.
#
# Configuration is gathered at the beginning of the script.
# =============================================================================
# Configuration
# =============================================================================
FTP_USER=card
FTP_PASS=card
FTP_IP=192.168.1.30
FTP_PORT=2121
DESTINATION=Card/ # Local folder where to save files
# List of folders to save
# example: LINK+=("/distant/dir" "dir2")
# will saved FTP folder "/distant/dir" in local folder "$DESTINATION/dir2"
LINK=()
LINK+=("DCIM" "DCIM")
LINK+=("Download" "Download")
# =============================================================================
echo "========================================================="
echo "Start synchronisation to ${DESTINATION}"
echo "========================================================="
find ${DESTINATION} -type f -exec chmod 644 {} \;
find ${DESTINATION} -type d -exec chmod 755 {} \;
for ((i=0; i<${#LINK[@]}; i+=2)); do
DISTANT_DIR=${LINK[i]}
LOCAL_DIR=${LINK[i+1]}
echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}"
mkdir -p "${DESTINATION}/${LOCAL_DIR}/"
if lftp ftp://${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT} -e "mirror -e -x .thumbnails -x "saved" \"${DISTANT_DIR}\" \"${DESTINATION}/${LOCAL_DIR}\" ; quit" ; then
echo "Success :)"
else
echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
fi
done
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
# Configuration file for run.sh
# =============================================================================
# Phone Configuration
# =============================================================================
PHONE_FTP_USER=ftp
PHONE_FTP_PASS=ftp
PHONE_FTP_IP=192.168.1.30
PHONE_FTP_PORT=2121
PHONE_DESTINATION="Phone/"
# List of folders to sync: pairs of (remote_dir, local_dir)
PHONE_LINKS=(
"/DCIM" "DCIM"
"/Pictures" "Pictures"
"/Download" "Download"
"/WhatsApp/Media/WhatsApp Video" "WhatsApp_Video"
"/WhatsApp/Media/WhatsApp Images" "WhatsApp_Images"
"/Documents" "Documents"
)
# =============================================================================
# Card Configuration
# =============================================================================
CARD_FTP_USER=card
CARD_FTP_PASS=card
CARD_FTP_IP=192.168.1.30
CARD_FTP_PORT=2121
CARD_DESTINATION="Card/"
# List of folders to sync: pairs of (remote_dir, local_dir)
CARD_LINKS=(
"DCIM" "DCIM"
"Download" "Download"
)
-59
View File
@@ -1,59 +0,0 @@
#!/bin/bash
set -e # Exit if error
# This script synchronizes data from FTP into local folder:
# - remove file that do not exist anymore in the FTP (mirror -e)
#
# No modification will be done in the FTP.
#
# Configuration is gathered at the beginning of the script.
# =============================================================================
# Configuration
# =============================================================================
FTP_USER=ftp
FTP_PASS=ftp
FTP_IP=192.168.1.30
FTP_PORT=2121
DESTINATION=Phone/ # Local folder where to save files
# List of folders to save
# example: LINK+=("/distant/dir" "dir2")
# will saved FTP folder "/distant/dir" in local folder "$DESTINATION/dir2"
LINK=()
LINK+=("/DCIM" "DCIM")
LINK+=("/Pictures" "Pictures")
LINK+=("/Download" "Download")
LINK+=("/WhatsApp/Media/WhatsApp Video" "WhatsApp_Video")
LINK+=("/WhatsApp/Media/WhatsApp Images" "WhatsApp_Images")
LINK+=("/Documents" "Documents")
# =============================================================================
echo "========================================================="
echo "Start synchronisation to ${DESTINATION}"
echo "========================================================="
find ${DESTINATION} -type f -exec chmod 644 {} \;
find ${DESTINATION} -type d -exec chmod 755 {} \;
for ((i=0; i<${#LINK[@]}; i+=2)); do
DISTANT_DIR=${LINK[i]}
LOCAL_DIR=${LINK[i+1]}
echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}"
mkdir -p "${DESTINATION}/${LOCAL_DIR}/"
if lftp ftp://${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT} -e "mirror -e -x .thumbnails -x "saved" \"${DISTANT_DIR}\" \"${DESTINATION}/${LOCAL_DIR}\" ; quit" ; then
echo "Success :)"
else
echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
fi
done
+53 -2
View File
@@ -2,6 +2,57 @@
set -e # Exit if error
# Load configuration
source "$(dirname "$0")/config.sh"
./phone_sync.sh
./card_sync.sh
# =============================================================================
# Sync function
# Usage: sync_ftp PREFIX
# PREFIX = PHONE or CARD (used to get config vars: ${PREFIX}_FTP_USER, etc.)
# =============================================================================
sync_ftp() {
local PREFIX=$1
local FTP_USER_var="${PREFIX}_FTP_USER"
local FTP_PASS_var="${PREFIX}_FTP_PASS"
local FTP_IP_var="${PREFIX}_FTP_IP"
local FTP_PORT_var="${PREFIX}_FTP_PORT"
local DESTINATION_var="${PREFIX}_DESTINATION"
local LINKS_NAME="${PREFIX}_LINKS"
local FTP_USER="${!FTP_USER_var}"
local FTP_PASS="${!FTP_PASS_var}"
local FTP_IP="${!FTP_IP_var}"
local FTP_PORT="${!FTP_PORT_var}"
local DESTINATION="${!DESTINATION_var}"
echo "========================================================="
echo "Start synchronisation to ${DESTINATION}"
echo "========================================================="
# Set permissions
find "${DESTINATION}" -type f -exec chmod 644 {} \;
find "${DESTINATION}" -type d -exec chmod 755 {} \;
# Get links array
eval "local LINKS=(\"\${$LINKS_NAME[@]}\")"
# Sync each folder pair
for ((i=0; i<${#LINKS[@]}; i+=2)); do
local DISTANT_DIR="${LINKS[i]}"
local LOCAL_DIR="${LINKS[i+1]}"
echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}"
mkdir -p "${DESTINATION}${LOCAL_DIR}/"
if lftp ftp://"${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT}" -e "mirror -e -x .thumbnails -x saved \"${DISTANT_DIR}\" \"${DESTINATION}${LOCAL_DIR}\" ; quit" ; then
echo "Success :)"
else
echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
fi
done
}
# =============================================================================
# Run sync for phone and card
# =============================================================================
sync_ftp PHONE
sync_ftp CARD