使用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
用lftp:
#!/bin/bash
lftp -u username,password ip << EOF
cd /home/xxx/xxx/what/you/want/
put what_you_want_to_upload
bye
EOF
从lftp手册:
-u [,] use the user/password for authentication
您可以使用mkdir创建目录.你可以像这样使用put命令几次:
put what_you_want_to_upload
put what_you_want_to_upload2
put what_you_want_to_upload3
你可以与再见关系密切
您可以检查文件夹是否存在,如下所示:
#!/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 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