【发布时间】:2016-11-21 10:15:28
【问题描述】:
我有这个脚本可以将文件上传到 FTP(我知道 FTP 不安全,尽管客户端坚持使用 FTP..)。它工作正常,但它的问题是无法识别上传时提供的路径,即使消息说它已成功上传,但没有上传任何内容。
所以脚本看起来像这样:
#!/bin/bash
HOST=host
USER=user
PASS=pass
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ftp -inv $HOST << EOF
user $USER $PASS
get
cd /path/in/ftp/
prompt
mput $DIR/*.csv
# End FTP Connection
bye
EOF
rm $DIR/*.csv
这里输出的是什么:
Connected to host.
220 You have connected to Client's FTP server.
?Invalid command
331 User name okay, need password.
230-Welcome user from ip. You are now logged in to the server.
230 User logged in, proceed.
Remote system type is UNIX.
Using binary mode to transfer files.
?Invalid command
250 Directory changed to "/path/in/ftp/"
?Invalid command
Interactive mode on.
mput /path/inv_numbers_2016-11-21_12_09.csv? 200 PORT command successful.
150 File status okay; about to open data connection.
226 Closing data connection. Transferred 140 bytes in 1 seconds. 0KB/second.
140 bytes sent in 0.00 secs (1395.1 kB/s)
?Invalid command
221 Session Ended. Downloaded 0KB, Uploaded 1KB. Goodbye user from ip.
现在,如果我将mput $DIR/*.csv 更改为mput *.csv,那么它可以工作(我得到与前一个相同的日志输出,除了它将路径显示为直接在脚本所在的目录中)。但这只有在我直接从它所在的目录运行脚本时才有效。
有什么想法吗?
【问题讨论】:
标签: bash csv file-upload ftp