简体   繁体   English

bash FTP脚本中的本地文件存在条件

[英]Local file existence condition in bash FTP script

I want to get a file from a server conditional on the non-existence of the file in the local directory. 我想从服务器获取文件,条件是本地目录中不存在该文件。 In the final script there will be many files but here is an example just using one. 在最终脚本中,将有许多文件,但是这里仅使用一个示例。

I'm trying this: 我正在尝试:

#!/bin/bash
HOST='a.b.c.d'
USER='anonymous'
PASSWD='pass'

ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
binary

!test -f filename && get /remotedir/remotefilename filename

bye
EOT

I get this error: +bash: get: command not found , presumably because get is called in the local rather than the in the FTP but I don't know how to fix this. 我收到此错误: +bash: get: command not found ,大概是因为在本地而不是在FTP中调用了get ,但是我不知道如何解决这个问题。

Try this: 尝试这个:

Replace 更换

!test -f filename && get /remotedir/remotefilename filename

by 通过

$(test -f filename && echo get /remotedir/remotefilename filename)

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

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