Wednesday, 7 August 2019

linux - How can I upload local changed files to an FTP server?


I use a PHP IDE that has no built-in ability to upload a project to a site.


So, I'm looking for common easy to use tool for Linux that would able to upload modified documents to the server instead of uploading of the whole site.


I also accept shell scripts that would be able to do this.



Answer



Install lftp if you don't have it yet. Then create a bash script containing the following:


#!/bin/bash
TARGET='/remote/folder'
SOURCE='/your/local/folder'
lftp -f "
open
user
lcd $SOURCE
mirror --reverse --delete --verbose $SOURCE $TARGET
bye
"

Replace , and with your actual data.


This will effectively sync your local files to the remote folder, deleting everything that doesn't exist locally anymore (this is the delete option). --reverse specifies that you want to actually update your remote folder instead of your local one.


Have a look at lftp's man page for more details. And always have a backup ready so you don't delete anything in case a command goes wrong.


This is adapted from this script here.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...