简体   繁体   English

如何在linux中使用shell脚本登录到ftp服务器?

[英]How to login to an ftp server using shell scripting in linux?

I want to login to my FTP server using shell scripting. 我想使用shell脚本登录我的FTP服务器。 I made a .sh file having contents as 我制作了一个内容为.sh的.sh文件

ftp open 172.31.1.45 ftp打开172.31.1.45

but it's not working. 但它不起作用。 The second command is not executing. 第二个命令没有执行。 Please help. 请帮忙。 I am new to linux so please forgive if this is a stupid question 我是linux的新手,所以如果这是一个愚蠢的问题,请原谅

try this: 试试这个:

#!/bin/sh
HOST="yourhost"
USER="user"
PASSWD="pass"
FILE="file.txt"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT

If it's just a matter of simple file transfers, you might want to look at using a tool like ncFTP, wget, or cURL, which can do file transfers in a single command. 如果只是简单文件传输的问题,您可能希望使用ncFTP,wget或cURL等工具,它可以在单个命令中进行文件传输。 Using these tools, you can simply pass the username, password, host address, source file, and destination file in one command. 使用这些工具,您只需在一个命令中传递用户名,密码,主机地址,源文件和目标文件即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM