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

随声附和 提交于 2019-12-06 07:31:02

问题


I want to login to my FTP server using shell scripting. I made a .sh file having contents as

ftp open 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


回答1:


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



回答2:


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. Using these tools, you can simply pass the username, password, host address, source file, and destination file in one command.



来源:https://stackoverflow.com/questions/19747345/how-to-login-to-an-ftp-server-using-shell-scripting-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!