我有一个文件,其中包含由行尾分隔的文件列表
$ cat file_list
file1
file2
file3我想使用FTP复制此文件列表
我该怎么做呢?我必须要写一个脚本吗?
发布于 2012-05-04 16:45:38
您可以很容易地将文件列表转换为ftp命令列表:
(echo open hostname.host;
echo user username;
cat filelist | awk '{ print "put " $1; }';
echo bye) > script.ftp然后你可以直接运行:
ftp -s script.ftp
或者可能(使用其他版本的ftp)
ftp -n < script.ftp
发布于 2012-05-04 16:44:08
这些东西- somecommand取决于你想要做什么-我不明白你的问题,对不起。
#!/bin/bash
# Iterate through lines in file
for line in `cat file.txt`;do
#your ftp command here do something
somecommand $line
done编辑:如果您真的想在多个文件中使用此路由(您不应该这样做!),您可以使用以下命令来代替somecommand $line
ncftpput -m -u username -p password ftp.server.com /remote/folder $linencftpput可能也会一次性上传任意数量的文件,但我还没有检查过。请注意,这种方法将对每个文件进行连接和断开连接!
发布于 2012-10-10 01:32:20
感谢你提供了一个很有帮助的例子,告诉我如何将文件列表提供给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>
byehttps://stackoverflow.com/questions/10445417
复制相似问题