Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LFTP - Create directory if it does not exist

Tags:

linux

bash

lftp

I would like to use LFTP to create a directory if it does not exist. It should be a "one-liner":

This does already work:

lftp -c "open -u user,pass server; mkdir /test

The

lftp -c "open -u user,pass server; mkdir -p /test

fails if the directory already exists:

mkdir: Zugriff nicht möglich:550-Can't create directory: File exists 16 files used (0%) - authorized: 50000 files 1286621 Kbytes used (0%) - authorized: 512000000 Kb (/test2)

But it does fail if the directory does already exist. How can I do this more elegant?

like image 688
MyFault Avatar asked Aug 25 '16 11:08

MyFault


2 Answers

You can use mkdir -f option to suppress the error message. The option is available starting with 4.5.2 version. The latest lftp version is 4.7.3.

like image 148
lav Avatar answered Sep 27 '22 16:09

lav


If you can't upgrade to the latest version of lftp, you can use this :

lftp -c "cd /my/new/directory || mkdir -p /my/new/directory"

It will create the directory only if it can't enter it.

like image 23
Julien Lirochon Avatar answered Sep 27 '22 16:09

Julien Lirochon