bash 你如何通过 shell 脚本连接到 FTP 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7285650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:42:21  来源:igfitidea点击:

How do you connect to FTP server via a shell-script

bashshellscripting

提问by Spencer

I am writing my first shell-script ever and I am trying to connect to an FTP server. However, I am utterly at a loss for how to do this. I tried a google search, but I am still stumped.

我正在编写我的第一个 shell 脚本,并且正在尝试连接到 FTP 服务器。但是,我完全不知道如何做到这一点。我尝试了谷歌搜索,但我仍然很难过。

I am trying to connect with a username and password (not a ssh id).

我正在尝试使用用户名和密码(不是 ssh id)进行连接。

Thanks for your help. Again this is my first shell-script ever.

谢谢你的帮助。这也是我有史以来的第一个 shell 脚本。

回答by touffy

The command man ftpshould give you the necessary pointers. This being said, this pagemight help you build a complete shell script

该命令man ftp应该为您提供必要的指示。话虽如此,此页面可能会帮助您构建完整的 shell 脚本

回答by Samir

Here how you connect to FTP server via a shell-script :

以下是如何通过 shell 脚本连接到 FTP 服务器:

nano MyConnectFTPScript.sh

#!/bin/sh
$HOST='hostAdresss'
$USER='NameOfUser'
$PASSWD='YourPass'
$FILEtoPut='myFile1'
$FILEtoGet='myFile2'
$FILEtoDelete='myFile3'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD

put $FILEtoPut
get $FILEtoGet
delete $FILEtoDelete

quit
END_SCRIPT
exit 0

chmod +x MyConnectFTPScript.sh

and execute : ./MyConnectFTPScript.sh

并执行:./MyConnectFTPScript.sh

I hope these will be helpful. Samir

我希望这些会有所帮助。萨米尔