这是我的bash文件:
#!/bin/bash
# FTP Vars
FTP_IP=IPv4
FTP_USERNAME=USERNAME
FTP_PASSWORD=PASSWORD
FTP_PATH=/SOME_PATH
# FTP Connection, Upload and Delete
function upload() {
ftp -n -v $FTP_IP << EOF
ascii
user $FTP_USERNAME $FTP_PASSWORD
prompt
cd $FTP_PATH
ls
bye
EOF
}
if upload
then echo 'done'
else echo 'not done'
fi
问题是,我输入的密码是正确还是错误并不重要,我在输出中看到done
,这意味着upload
函数工作正常。
让我展示一下输出:
正确的凭据:
Connected to IPv4.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 23:32. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
200 TYPE is now ASCII
331 User group OK. Password required
230-This server supports FXP transfers
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
Interactive mode off.
250 OK. Current directory is /SOME_PATH
229 Extended Passive mode OK (|||35332|)
150 Accepted data connection
drwxr-xr-x 7 1047 group 92 May 1 12:49 .
drwx--x--- 8 1047 1003 181 May 1 21:29 ..
drwxr-xr-x 3 1047 group 24 May 1 12:49 dir1
drwxr-xr-x 3 1047 group 24 May 1 12:49 dir2
226-Options: -a -l
226 7 matches total
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
done
凭据不正确:
Connected to IPv4.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 23:36. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
200 TYPE is now ASCII
331 User group OK. Password required
530 Login authentication failed
Login failed.
Interactive mode off.
530 You aren't logged in
530 You aren't logged in
530 You aren't logged in
530 You aren't logged in
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
done
1条答案
按热度按时间8i9zcol21#
ftp
命令不会根据命令的成功设置退出状态。在我的自动FTP上传脚本中,我使用
lftp
命令,但您也可以使用curl
或wget
。