Linux实现文件上传ftp服务器脚本代码

华盟原创文章投稿奖励计划

工作期间,每次将文件上传至ftp服务器时,均需要手工输入ip、用户名、密码等,因此,考虑编写脚本完成文件的上传任务。具体的脚本sync.sh如下:

#!/bin/bash
source ~/.bashrc
# 模拟进入ftp命令行模式,其中EOF表示退出标记符
ftp -niv <<- EOF
# 根据ftp的ip地址与端口号,连接ftp服务器
open ip port
# 输入用户名与密码
user userName password
# 以bin模式进行传输,与ASCII模式有区别,使用bin模块能够防止乱码问题
bin
# 上传文件
get $1
# 结束
bye
#退出
EOF

然后将该脚本sync.sh加入环境变量,每次只需执行 sync.sh filename即可,具体的执行过程如下:

Connected to *.*.*.*.
220 Microsoft FTP Service
331 Password required for userName.
230 User logged in.
Remote system type is windows_NT.
200 Type set to I.
local: filename remote: filename
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
112089125 bytes received in 44.62 secs (2453.3 kB/s)
221 Goodbye.

本文原创,作者:小龙,其版权均为华盟网所有。如需转载,请注明出处:https://www.77169.net/html/95596.html

发表评论