简体   繁体   English

BASH:如何通过ftp传递文件名变量

[英]BASH: how to ftp a variable of filenames

I am trying to upload multiple files to a remote server via FTP. 我正在尝试通过FTP将多个文件上传到远程服务器。

The file names have been extracted into a variable and are separated by a single space, example: 文件名已提取到变量中,并用单个空格分隔,例如:

testVideo.mp4 testVideo2.mp4

How can I get these file names to be used by 'put' or 'mput' for example to transfer the files themselves to the remove server? 如何获得这些文件名以供“ put”或“ mput”使用,例如将文件本身传输到删除服务器?

This works: 这有效:

var="testVideo.mp4 testVideo2.mp4"
mput $var

Much obliged for any help. 非常有必要提供任何帮助。

Using a string to hold the list of file names is fundamentally flawed, since a filename could contain a space. 从根本上说,使用字符串保存文件名列表是有缺陷的,因为文件名可以包含空格。 (Does var="foo bar.mp4 baz.mp4" contain two or three filename?) Instead, use an array: var="foo bar.mp4 baz.mp4"包含两个或三个文件名?)而是使用数组:

var=( "testVideo 1.mp4" "testVideo 2.mp4" )
mput "${var[@]}"

The quoted expansion of the array guarantees that if any element of the array itself contains whitespace, that element will be properly quoted as a single argument to mput . 带引号的数组扩展保证,如果数组本身的任何元素包含空格,则该元素将被正确引用为mput的单个参数。

ncftpput can accept a list of local filenames, and ftp them to a remote host. ncftpput可以接受本地文件名列表,并将它们通过ftp传送到远程主机。 See http://www.ncftp.com/ncftp/doc/ncftpput.html 参见http://www.ncftp.com/ncftp/doc/ncftpput.html

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

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