ftp上传下载记录

来源:互联网 发布:htc m8 刷Windows教程 编辑:程序博客网 时间:2024/05/17 21:55

1,准备ftp环境

下载最新的ftp客户端:https://filezilla-project.org/ftp/001.png,选择linux下面的版本,如002.png所示:在window10下面下载,使用wget http://sourceforge.net/projects/filezilla/files/FileZilla_Client/3.26.1/FileZilla_3.26.1_i586-linux-gnu.tar.bz2在linux命令行里面下载。解压缩,tar -xvf FileZilla_3.26.1_i586-linux-gnu.tar.bz2安装ftp: yum install vsftpd -y启动:service vsftpd start尝试ftp命令,报错[root@hch_test_dbm1_121_62 bin]# ftp-bash: ftp: command not found[root@hch_test_dbm1_121_62 bin]#直接下载ftp安装包 wget http://mirror.centos.org/centos/6/os/x86_64/Packages/ftp-0.17-54.el6.x86_64.rpm然后安装[root@hch_test_dbm1_121_62 soft]# rpm -ivh ftp-0.17-54.el6.x86_64.rpm Preparing...                ########################################### [100%]   1:ftp                    ########################################### [100%][root@hch_test_dbm1_121_62 soft]# 安装报错libc.so.6 is needed by ftp-0.17-35.el5.i386去安装rpm –Uvh http://mirror.centos.org/centos/6/os/x86_64/Packages/glibc-2.12-1.132.el6.x86_64.rpm尝试ftp操作[root@hch_test_dbm1_121_62 soft]# ftpftp> 



2,自动登录下载

#!/bin/bashftp -n<<!open 120.132.27.91 10000user downdata RakudespuH3bAk+ruybinarycd uplcd /home/mysql/binlogspromptmget mysql-bin*closebye!



3,自动登录上传

#本地的/home/databackup to ftp服务器上的/home/data#####!/bin/bashftp -n<<!open 192.168.1.171user guest 123456binaryhashcd /home/datalcd /home/databackuppromptmput *closebye!



4,涉及的技巧

#!/bin/bash#提取文件名,删除后缀。file_name="text.gif"name=${file_name%.*}echo file name is: $name输出结果:file name is: test从右边到左边的匹配操作 :% 和 %% 操作符的示例[root@hch_test_dbm1_121_62 load_binlog]# filename=mysql-bin.000110.zip[root@hch_test_dbm1_121_62 load_binlog]# name=${filename%.*}[root@hch_test_dbm1_121_62 load_binlog]# echo $namemysql-bin.000110[root@hch_test_dbm1_121_62 load_binlog]# 看到输出结果是没有.zip的文件名mysql-bin.000110------------------------------------------------有些脚本要根据文件名进行各种处理,有时候需要保留文件名抛弃文件后缀,也有时候需要文件后缀不要文件名,这类提取文件部分的操作使用shell的内建功能就能实现。需要用到的几个操作符有:%、%%、#、##。从右向左匹配 :% 和 %% 操作符的示例#!/bin/bash#提取文件名,删除后缀。file_name="text.gif"name=${file_name%.*}echo file name is: $name输出结果:file name is: test# ${VAR%.* }含义:从$VAR中删除位于 % 右侧的通配符左右匹配的字符串,通配符从右向左进行匹配。现在给变量 name 赋值,name=text.gif,那么通配符从右向左就会匹配到 .gif,所有从 $VAR 中删除匹配结果。# % 属于非贪婪操作符,他是从左右向左匹配最短结果;%% 属于贪婪操作符,会从右向左匹配符合条件的最长字符串。file_name="text.gif.bak.2012"name=${file_name%.*}name2=${file_name%%.*}echo file name is: $nameecho file name is: $name2输出结果:file name is: test.gif.bak    //使用 %file name is: test            //使用 %%操作符 %% 使用 .* 从右向左贪婪匹配到 .gif.bak.2012从左向右匹配:# 和 ## 操作符示例#!/bin/bash#提取后缀,删除文件名。file_name="text.gif"suffix=${file_name#*.}echo suffix is: $suffix输出结果:suffix is: gif# ${VAR#*.} 含义:从 $VAR 中删除位于 # 右侧的通配符所匹配的字符串,通配符是左向右进行匹配。# 跟 % 一样,# 也有贪婪操作符 ## 。file_name="text.gif.bak.2012.txt"suffix=${file_name#*.}suffix2=${file_name##*.}echo suffix is: $suffixecho suffix is: $suffix2输出结果:suffix is: text.gif.bak.2012     //使用 #suffix2 is: txt                  //使用 ##操作符 ## 使用 *. 从左向右贪婪匹配到 text.gif.bak.2012示例2,定义变量 url="www.1987.name"echo ${url%.*}      #移除 .* 所匹配的最右边的内容。www.1987echo ${url%%.*}     #将从右边开始一直匹配到最左边的 *. 移除,贪婪操作符。wwwecho ${url#*.}      #移除 *. 所有匹配的最左边的内容。1987.nameecho ${url##*.}     #将从左边开始一直匹配到最右边的 *. 移除,贪婪操作符。name
原创粉丝点击