美文网首页
Ftp备份单个文件

Ftp备份单个文件

作者: yahzon | 来源:发表于2019-04-03 18:31 被阅读0次

脚本和ftp.txt
脚本用于启动cmd 执行ftp
ftp.txt用于记录ftp依次需要执行的命令
脚本:E:\script\runftp.bat

@echo off
ftp -s:E:\script\ftp.txt

E:\script\ftp.txt:

open 192.168.xx.xx
ftpusername
pwd
cd .\mybak
put D:\bak\mysqlbak\xxx.xx
bye

Linux版:

  1. cron定时任务
cron -e  编辑定时任务
cron -l  列出定时任务

 # Example of job definition:
 # .---------------- minute (0 - 59)
 # | .------------- hour (0 - 23)
 # | | .---------- day of month (1 - 31)
 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
 # | | | | |
 # * * * * * user-name command to be executed

编辑后,重启服务生效

/bin/systemctl restart crond.service
  1. ftp脚本及说明
#!/bin/bash            --这个使用bash执行
ftp -n<<!                -- -n表示不受.netrc文件中的配置影响 !表示即时文件,后面以!表示即时文件结束
open xxx.xxx.xxx.xxx  -- ftp连接到服务器,xxx为ip地址
user username password --登录ftp, 并提供用户名和密码
binary       --以二进制传输
hash        --每传输1024字节,输出一个#符号
prompt off     --使用mput命令时,不再询问y/n
cd /xx/xxx    -- 服务器端进入到存放文件的目录
lcd /xxx/xxx   --客户端,进入待上传文件所在的目录
mput *   --把本地目录中的所有文件上传到服务器
close    -- 与open相反,中断服务器连接
bye
!       --即时文件结束
  1. 实战脚本
open 192.168.xxx.xxx port
$username
$pwd
binary
hash
prompt off
cd /svn_64/Repositories/$yourfolder
lcd D:\Repositories\$yourfolder
mput *
close
bye

相关文章

网友评论

      本文标题:Ftp备份单个文件

      本文链接:https://www.haomeiwen.com/subject/buxtiqtx.html