[英]FTP upload in bash script
I tried to write a bash script which upload a file to an ip address with ftp connection, but i have an issue or something like that.我尝试编写一个 bash 脚本,该脚本使用 ftp 连接将文件上传到 ip 地址,但我遇到了问题或类似问题。 I have a.txt file with a lot of line.
我有一个包含很多行的 .txt 文件。 Every line have an ip address, nothing else just the ip address.
每行都有一个 ip 地址,没有别的只是 ip 地址。 So i want to read the ip address from the text file and use it as a variable.
所以我想从文本文件中读取 ip 地址并将其用作变量。 This is my ugly code:
这是我丑陋的代码:
#!/bin/bash
input="example.txt";
user="admin"
pass="12345678"
filename="example.src"
while IFS= read -r line; do
connection
done < $input
connection(){
ftp -i -n $line
user $user $pass
put $filename
bye
}
With the first ip address int the first line the connection and the upload is successful but the other lines got error like this:使用第一个 ip 地址 in 第一行连接和上传成功,但其他行出现如下错误:
Login incorrect
Login failed.
Please login with USER and PASS
Passive mode refused.
Commands of ftp can be written in a here-document. ftp的命令可以写在here-document中。
#!/bin/bash
connection(){
ftp -i -n $line << EOS
user $user $pass
put $filename
bye
EOS
}
input="example.txt";
user="admin"
pass="12345678"
filename="example.src"
while IFS= read -r line; do
connection
done < $input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.