在linux shell中使用ftp命令来实现自动登陆、上传与下载
来源:互联网 发布:泰安焦点网络待遇 编辑:程序博客网 时间:2024/04/29 10:55
前段时间有个需求,需要利用crontab定时往某个FTP上传文件,原以为linux中带的ftp命令只支持交互式的操作,没法在命令行下使用,所以后来打算利用PHP中提供的ftp命令来做,但是很不幸的发现ftp模块不是PHP的标准模块,还需要自己编译,比较麻烦,后来本着试试看的态度去网上搜了一把,结果发现还真是可以在shell下来利用ftp命令。
首先我们来看ftp的两个参数
-n Restrains ftp from attempting ''auto-login'' upon initial connection. If auto-login is enabled, ftp will check
the .netrc (see below) file in the user's home directory for an entry describing an account on the remote
machine. If no entry exists, ftp will prompt for the remote machine login name (default is the user identity on
the local machine), and, if necessary, prompt for a password and an account with which to login.
-u Restrains ftp from attempting ''auto-authentication'' upon initial connection. If auto-authentication is
enabled, ftp attempts to authenticate to the FTP server by sending the AUTH command, using whichever authentica-
tion types are locally supported. Once an authentication type is accepted, an authentication protocol will pro-
ceed by issuing ADAT commands. This option also disables auto-login.
显然默认情况下,我们不加这两个参数来使用ftp命令的话,如ftp localhost,那么就直接被要求用户名和密码,这样子就走回到交互式的老路上去了。因此要使用非交互式就必须加-n这个参数,(-u不是必须的,如果不加的话,对于一些服务器可能会报一个warning,但是不影响功能)。最终shell脚本如下所示这样子
ftp –u –n $HOST $PORT << CMDS
user $USERNAME $PASSWORD
lcd $DST_FOLDER
put $DST_FILENAME
bye
TAG
这段脚本就告诉ftp命令,不自动登陆,连接到$HOST的$PORT端口,然后依次运行TAG里标注的命令
我们这里是先运行user命令来登陆,然后进入要上传文件的目录,最后开始上传,上传完成后断开连接。
- 在linux shell中使用ftp命令来实现自动登陆、上传与下载
- 在linux shell中使用ftp命令来实现自动上传与下载
- 在linux shell中使用ftp命令来实现自动上传与下载
- Linux shell中使用ftp自动下载上传文件
- linux中使用shell脚本自动登录ftp服务器下载上传文件。
- Linux使用Shell脚本实现ftp自动上传
- Linux FTP自动登陆下载备份,上传文件脚本
- shell脚本,自动登陆ftp,下载文件
- shell实现ftp自动上传
- python socke ftp功能实现 shell命令,上传,下载
- 使用FTP命令自动完成文件的上传和下载
- Linux下使用Shell脚本实现ftp的自动上传下
- 如何在命令行中使用 ftp 命令上传和下载文件
- linux ftp 命令详解和自动上传脚本实现
- linux ftp 命令详解和自动上传脚本实现
- linux ftp 命令详解和自动上传脚本实现
- linux ftp上传与下载
- linux shell ftp脚本自动上传脚本
- minicom能输出串口信息不能输入
- Objective-C超越C++,成为第三大受欢迎编程语言
- Java 序列化的高级认识
- hibernate 使用的集合类(list和bag)
- extjs ajax 通用写法
- 在linux shell中使用ftp命令来实现自动登陆、上传与下载
- 将一张表的字段根据条件更新到另一张表的一个字段中去
- cocos2d 安装 和 卸载
- c++输出格式控制
- Eclipse导入到web项目没有run on server
- python PIL ImportError: The _imagingft C module is not installed
- 我的定投计划
- 使用Sqlserver事务发布实现数据同步
- 错排公式