Linux shell应用2-自动下载文件

本文介绍了如何使用Linux Shell脚本结合ftp和lftp命令自动下载文件,详细讲解了ftp和lftp的基本用法,以及如何设置cron定时任务来定期执行下载任务。示例脚本演示了从ftp服务器筛选并下载RMVB电影的过程,并提示了如何避免重复下载及通过NFS与Windows共享文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 概述

Linux强大的命令行,能够完成各种不同的功能。然而,如果只是无休止的输入命令来完成功能,那么就太有点费事了。那么怎么能够解决这个问题了? Linux shell脚本给我们提供了答案。通过shell编程可以把命令进行组合,去自动的完成管理与执行任务。而不需要一次又一次的输入命令。这篇文章中,主要介绍一下,怎么利用shell脚本去完成自动下载文件的功能。

 

2. 基本知识

(1) Linux shell编程基础-包括awk,sed,正则表达式,在前面已经介绍过了。

(2)ftp,lftp

FTP是一个文件传输协议,分为主动传输与被动传输,而传送的方式有binary和acsii两种,get用于下载文件,put用于上传文件。

 

 FTP  is the user interface to the ARPANET standard File Transfer Proto-
       col.  The program allows a user to transfer files to and from a  remote
       network site

 

-n  禁止自动登录

-i  关闭交互式ftp,默认情况下ftp是一种交互式操作

 

-n     Restrains  ftp  from attempting ‘‘auto-login’’

 

-i     Turns off interactive prompting during multiple file  transfers.

 

 ! [command] [args]]
              Invoke  an interactive shell on the local machine.  If there are
              arguments, the first  is  taken  to  be  a  command  to  execute
              directly, with the rest of the arguments as its arguments.

 

! -代表回到shell脚本

 

 

get remote-file [local-file]
              Retrieve the file remote-file and store it on the local machine.
              If  the  local  fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值