bash 如何使用命令通过 FTP 覆盖文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27166518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to overwrite files over FTP using command?
提问by Deep Shah
I have written such a shell script which uploads files over ftp to my deployment server . This script working perfectly if you want full-deployment i.e entire project in one go . but problem is when i change specific file on local machine and now i want it to overwrite existing same file on server using ftp it's not overwriting.
我编写了这样一个 shell 脚本,它通过 ftp 将文件上传到我的部署服务器。如果您想要一次全面部署,即整个项目,此脚本将完美运行。但问题是当我更改本地机器上的特定文件,现在我希望它使用 ftp 覆盖服务器上现有的相同文件时,它不会被覆盖。
MKDIR=`for directory in $FOLDERS; do echo "mkd \"${directory}\""; done`
DELETE=`for file in $DFILES; do echo "delete \"${file}\""; done`
ATTACH=`for file in $FILES; do echo "put \"${file}\""; done`
IFS=$ORIGIFS
# Send updates to server
ftp -nv <<EOF
open $FTPHOST
user $FTPUSER $FTPPASS
binary
cd $FTPDIR
$MKDIR
$ATTACH
quit
EOF
Where: FOLDERS:contains directories to create, DELETE is string which has deleted files list , ATTACH has list of files that has been modified and needs to be overwritten on server that are exist.
其中: FOLDERS:包含要创建的目录,DELETE 是已删除文件列表的字符串,ATTACH 是已修改并需要覆盖的服务器上存在的文件列表。
After that when i run it second time after modification in existing files :
之后,当我在修改现有文件后第二次运行它时:
local: ./testproject/trunk/test.php ./svnupdate.txt remote: ./testproject/trunk/test.php ./svnupdate.txt
local: ./testproject/trunk/test.php ./svnupdate.txt: No such file or directory
采纳答案by Deep Shah
I found my answer .
我找到了答案。
Problem statement in my script :
我的脚本中的问题陈述:
ATTACH=`for file in $FILES; do echo "put \"${file}\""; done`
where i create list of files to upload.But this code concatenate each file names as told by @Jdamian. @Jdamian thanks for point out my mistake.
我在其中创建要上传的文件列表。但是此代码按照@Jdamian 的指示连接每个文件名。@Jdamian 感谢您指出我的错误。
Solution:
解决方案:
ATTACH=`for file in $FILES
do
echo "put $file"
done`