Bash

Bash FTP 登錄到 Microsoft FTP 服務,命令無效

  • May 18, 2015

這是我的腳本。如您所見,它在連接到遠端 FTP 伺服器後僅執行 1 個命令 (cd /)。這很簡單……但它不起作用並給我“無效命令”。

我不明白為什麼。

#!/bin/bash

HOST=xxx             #This is the FTP servers host or IP address.
USER=xxx                     #This is the FTP user that has access to the server.
PASS=xxx              #This is the password for the FTP user.

# Call 1. Uses the ftp command with the -inv switches. 
#-i turns off interactive prompting. 
#-n Restrains FTP from attempting the auto-login feature. 
#-v enables verbose and progress. 

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS

pass

# Call 3. I change to the directory where I want to put or get
cd /

# Call4.  Here I will tell FTP to put or get the file.
#put...

# End FTP Connection
bye

EOF

這是輸出:

Connected to [IP]
220 Microsoft FTP Service
?Invalid command
331 Password required for logweb.
230 User logged in.
Remote system type is Windows_NT.
Passive mode on.
?Invalid command
250 CWD command successful.
?Invalid command
?Invalid command
?Invalid command
221 Goodbye.

“*無效命令”*錯誤是由這些#行引起的。ftp不將 辨識為#註釋前綴。

如果您需要腳本中的註釋,您可以濫用轉義到 shell 命令!並在其後添加 shell 註釋:

!# This is comment

除此之外,我相信您腳本中的所有命令都已執行,儘管您聲稱只有一個是:

> user $USER $PASS
< 331 Password required for logweb.
< 230 User logged in.

> cd /
< 250 CWD command successful.

> bye
< 221 Goodbye.

引用自:https://serverfault.com/questions/676075