0. Manual of mget
lftp :~> ? mget
- -c continue, resume transfer
- -d create directories the same as in file names and get the
files into them instead of current directory
- -E delete remote files after successful transfer
....
1. DELETED REMOTE FILE
The problem of deleted remoted file at option -E :
mget -E $REGEX
change it to mget $REGEX
2. MOVE FILE
mv
command to rename file
mmv
command to move file
If there problem with moving, it usualy because credentials,
like fileA.txt (made by userA), Folder_Backup_B(made by userB),
but you move fileA.txt to Folder_Backup_B and get mmv: Access failed: 550 Rename failed.
mmv need same user (or power user like root) that create / copy / move
In my test I have Directory :
Remote Directory
- /home/tyacode/test_ftp #REMOTE_DIR
- /home/tyacode/backup #REMOTE_BACKUP_DIR
When use lftp, I can't access backup folder from source /home, So I modify variable :
REMOTE_DIR="/home/tyacode/test_ftp/"
REMOTE_BACKUP_DIR="../backup/"
Maybe different scenario if you use hosting ftp
3. MODIFIED SCRIPT
#!/bin/bash
PROTOCOL="ftp"
URL="server.example.com"
USER="user"
PASS="password"
REGEX="*.txt"
LOG="/home/user/downloads/script.log"
LOCAL_DIR="/home/user/downloads"
REMOTE_DIR="dir/remote/server/file_directory"
REMOTE_BACKUP_DIR="dir/remote/server/backup_directory"
cd $LOCAL_DIR
if [ ! $? -eq 0 ]; then
echo "$(date "+%d/%m/%Y-%T") Cant cd to $LOCAL_DIR. Please make sure this local directory is valid" >> $LOG
fi
lftp $PROTOCOL://$URL <<- DOWNLOAD
user $USER "$PASS"
cd $REMOTE_DIR
mget $REGEX
mmv $REGEX $REMOTE_BACKUP_DIR
DOWNLOAD
if [ ! $? -eq 0 ]; then
echo "$(date "+%d/%m/%Y-%T") Cant download files. Make sure the credentials and server information are correct" >> $LOG
fi
mmv
is the right command to use to move the remote files afterwards; what exactly have you tried and what happened instead of what you wanted? – frabjous Mar 18 '22 at 23:41