bash 上传文件到远程服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4880163/
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-17 23:23:17  来源:igfitidea点击:

Upload file to remote server

linuxbashfile-uploadftp

提问by Alex

Have a problem. I need to upload file to remote ftp server using linux bash.. smth like this: cp file.tar.gz ftp://username:password@host/file.tar.gzCan it be done?

有一个问题。我需要使用 linux bash 将文件上传到远程 ftp 服务器..像这样: 可以做到吗?cp file.tar.gz ftp://username:password@host/file.tar.gz

Thanks in advance, Alex

提前致谢,亚历克斯

回答by woodleader

I would use http://www.ncftp.com/for this.

我会为此使用http://www.ncftp.com/

//see comment => "Specifically, take a look at ncftpput."

//see comment => "具体看一下ncftpput。"

回答by ajpyles

You can use just plain ftp + bash for this.

为此,您可以仅使用普通的 ftp + bash。

Bash script begin:

Bash 脚本开始:

echo "put $1" > commands.txt;

echo "put $1" > commands.txt;

echo "quit" >> commands.txt;

回声“退出”>>commands.txt;

ftp user@ftp://username:password@host < commands.txt

ftp user@ftp://username:password@host < commands.txt

Bash script end.

Bash 脚本结束。

Put that in ftp.sh. run it like ./ftp.sh file.tar.gz. this will upload to the ftp server.

把它放在 ftp.sh 中。像 ./ftp.sh file.tar.gz 一样运行它。这将上传到 ftp 服务器。