bash - 我想将文件通过 FTP(放入)到我在 Bash 中使用 "find"命令找到的目录中

标签 bash ftp find put

ftp -inv $HOST >> $TMPLOGFILE 2>&1 << ENDFTP
user $USER $PASS
binary
cd gpeh
lcd gpeh
put nameoffile *this is where I want the results of the "find" to go*
bye
ENDFTP

上面是我用于 ftp 的代码,下面是一个示例查找脚本。

find ./gpeh

所以基本上我想做的就是获取主机“gpeh”文件夹中的所有文件,然后将它们放入远程计算机“gpeh”文件夹中。有时文件数会是 1(嗯,在大多数情况下应该是 1,唯一不会是 1 的情况是前一小时的 ftp 失败,所以原始文件仍然存在,并且新文件也存在)这个小时添加),有时会更多。

如果我只是想说删除使用“find”命令在 gpeh 文件夹中找到的文件,我可以使用

find ./gpeh | xargs delete "and whatever conditions here"

但是我无法在 FTP 中执行此操作(或者也许可以),所以我真的不知道该怎么做。

提前感谢他

最佳答案

尝试以下方法

#!/bin/bash
PUT_FILES=$(find . -name "*" -printf "put %p\n")

ftp -inv $HOST >> $TMPLOGFILE 2>&1 << ENDFTP
user $USER $PASS
binary
cd gpeh
lcd gpeh
$PUT_FILES
bye
ENDFTP

说明

  • 查找 . -name "*"-printf "put %p\n" 在当前目录.任何名称文件"*",打印输出格式为“输入%p\n”
  • PUT_FILES=$(...) 将输出捕获到变量。
  • $PUT_FILES 将通过 ftp 展开并执行。

关于bash - 我想将文件通过 FTP(放入)到我在 Bash 中使用 "find"命令找到的目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752592/

相关文章:

python - 在单元测试中模拟 FTP

linux - 使用 Linux Find 并将内容通过管道传送到 S3 存储桶

python - 如何使用 Beautiful Soup 的 find() 代替 find_all() 以获得更好的运行时间

C++ Vector Find() 重载运算符 - 错误

bash - SHELL - IF 语句中的 AND 操作

linux - 如何在 bash_profile 文件中添加导出语句?

linux - 如何用sed替换静态位置的字符串并且不删除空格

linux - 在 bash 循环中读取响应

ftp - 由于政策原因,clickonce ftp 发布被拒绝

python - Proftpd 验证上传完成