简体   繁体   English

sftp 上传 bash 忽略文件

[英]sftp upload bash ignore files

I try to achieve some semi-automatic sftp upload/deployment.我尝试实现一些半自动的sftp上传/部署。 The main key is NOT to upload all files.主要的关键是不要上传所有文件。 I do not know which files to upload but I know which files not to upload.我不知道要上传哪些文件,但我知道不要上传哪些文件。

My bash script looks like:我的 bash 脚本如下所示:

#!/bin/bash

IP="123.123.123.123"
HOSTNAME="ftp.my-host.com"
PATH="subdirectory"

sftp username@$HOSTNAME:$PATH < "sftp-pattern"

in the sftp-pattern file i want to store my sftp commands.sftp-pattern文件中,我想存储我的 sftp 命令。 But I could not find any hints how to ignore several patterns.但是我找不到任何关于如何忽略几种模式的提示。 like *.sql .*.sql

Ideally i'd ignore everything that is gitignored.理想情况下,我会忽略 gitignored 的所有内容。

I do NOT have an ssh connection.没有ssh 连接。

Since you are using a shell script, you could use a loop.由于您使用的是 shell 脚本,因此您可以使用循环。 Something like this should work.像这样的事情应该有效。

#!/bin/bash

IP="123.123.123.123"
HOST="ftp.my-host.com"
DIR="/tmp/"

for f in `/bin/ls $DIR`
do
  if echo $f | /usr/bin/grep  '.sql' > /dev/null
  then
    echo SKIPPING $f
  else
   sftp username@$HOST:$DIR/$f
  fi
done

The answer should be git-ftp as @Clijsters mentioned.答案应该是@Clijsters 提到的git-ftp It is more feature rich and needs no fiddeling around with loops and pipes.它的功能更丰富,不需要摆弄循环和管道。

dwrights solution is working though, if it is ONLY sql that you want to exclude. dwrights解决方案正在不过,如果它只是SQL要排除。

Thanks!!谢谢!!

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

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