I'm trying to delete a file from an FTP server in my shell scrip using LFTP, but for some reason it will not use my variables, and takes them as literals.
The code:
USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"
lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u $USERNAME,$PASSWORD $SERVER
What I want it to do is run:
lftp -e 'rm /thebackups/uselessfile.obsolete; bye' -u theuser,verygoodpassword example.com
But instead it runs:
lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u theuser,verygoodpassword example.com
And of cause it can not find the literal file "/${BACKUPDIR}/${FILETODELETE}" on the FTP server and complains thus.
What am I doing wrong???
Cheers!
You can launch lftp by typing just lftp and then using an open command to take you to your target site or you can provide the target's name on the same line as lftp like I did.
Special Features. LFTP stands out from most other command-line FTP clients with advanced features such as recursive mirroring and the ability to update entire directory trees and manage bookmarks. Several simultaneous sessions to different servers are implemented by assigning commands to slots in a separate shell.
That's because you are using simple quote instead of double quotes.
Change this and will work
USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"
lftp -e "rm /${BACKUPDIR}/${FILETODELETE}; bye" -u $USERNAME,$PASSWORD $SERVER
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With