2

我的文件包含由行尾分隔的文件列表

$ cat file_list
file1
file2
file3

我想用 FTP 复制这个文件列表

我怎样才能做到这一点 ?我必须写一个脚本吗?

4

3 回答 3

9

You can turn your list of files into list of ftp commands easily enough:

(echo open hostname.host; 
 echo user username; 
 cat filelist | awk '{ print "put " $1; }'; 
echo bye) > script.ftp

Then you can just run:

ftp -s script.ftp

Or possibly (with other versions of ftp)

ftp -n < script.ftp

于 2012-05-04T08:45:38.317 回答
2

Something along these lines - the somecommand depends on what you want to do - I don't get that from your question, sorry.

#!/bin/bash
# Iterate through lines in file
for line in `cat file.txt`;do
#your ftp command here do something    
 somecommand $line
done

edit: If you really want to persue this route for multiple files (you shouldn't!), you can use the following command in place of somecommand $line:

ncftpput -m -u username -p password ftp.server.com /remote/folder $line

ncftpput propably also takes an arbitrary number of files to upload in one go, but I havn't checked it. Notice that this approach will connect and disconnect for every single file!

于 2012-05-04T08:44:07.613 回答
2

感谢有关如何将文件列表提供给 ftp 的非常有用的示例。这对我来说效果很好。

在 Linux (CentOs 5.5) 中创建我的 ftp 脚本后,我运行该脚本:

ftp –n < ../script.ftp

我的脚本(更改名称以保护无辜者)开头是:

open <ftpsite>
user <userid> <passwd>
cd <remote directory>
bin
prompt
get <file1>
get <file2>

并以:

get <filen-1>
get <filen>
bye
于 2012-10-09T17:32:20.057 回答