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 <user>[,<pass>] 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
你可以关闭与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