File transfer using lftp in bash script

I have server A test-lx, and server B test2-lx, I want to transfer files from server A to server B. When transferring files, I will need to create a driectory only if it does not exist, how can I check if the directory exists during the lftp connection? How can I output several files in one command, and not do it in 2 lines. Can i usefind -maxdepth 1 -name DirName

Here is my code:

lftp -u drop-up,1Q2w3e4R   ftp://ta1bbn01:21 << EOF

cd $desFolder
mkdir test
cd test
put $srcFil
put $srcFile

bye 
EOF
+4
source share
2 answers

Easy way with ftp:

#!/bin/bash

ftp -inv ip << EOF
user username password

cd /home/xxx/xxx/what/you/want/
put what_you_want_to_upload

bye
EOF

With lftp:

#!/bin/bash

lftp -u username,password ip << EOF

cd /home/xxx/xxx/what/you/want/
put what_you_want_to_upload

bye
EOF

From the lftp manual:

-u <user>[,<pass>]  use the user/password for authentication

You can use mkdir to create a directory. And you can use the put command several times, for example:

put what_you_want_to_upload
put what_you_want_to_upload2
put what_you_want_to_upload3

And you can close the connection with bye


, :

#!/bin/bash
checkfolder=$(lftp -c "open -u user,pass ip; ls /home/test1/test1231")

if [ "$checkfolder" == "" ];
then
echo "folder does not exist"
else
echo "folder exist"
fi

lftp:

-c <cmd>            execute the commands and exit

.


, , . , :

#!/bin/bash
checkfolder=$(lftp -c "open -u user,pass ip; ls /home/test1/test2")

if [ "$checkfolder" == "" ];
then

lftp -u user,pass ip << EOF

mkdir test2
cd test2
put testfile.txt
bye
EOF

else

echo "The directory already exists - exiting"

fi
+12

, phe, , ls/foldername " ", . ,

#!/bin/bash
checkfolder=$(lftp -c "open -u user,pass ip; ls | grep /test1231")

if [ "$checkfolder" == "" ];
then
echo "folder does not exist"
else
echo "folder exists"
fi

, , . .

#!/bin/bash
checkfolder=$(lftp -c "open -u user,pass ip; find | grep home/test1/test1231")

if [ "$checkfolder" == "" ];
then
echo "folder does not exist"
else
echo "folder exists"
fi
+1

Source: https://habr.com/ru/post/1568867/


All Articles