为了快速将项目中开发的补丁程序通过ftp快速上传到linux下,感觉每次用flashFxp等工具麻烦),写了个简单的批处理,与大家分享一下。
将以下代码保存为.bat格式的文件,每次将要上传的补丁保存在规定的本地目录中,
只要双击执行此文件就能上传到你的指定目录上。
说明:
192.168.1.1 ftp ip 地址
21 端口
username 用户名
password 密码
temp.txt 保存ftp信息的临时文件,上传后删除
C:\Documents and Settings\user\桌面\patch\upload_dir\1.zip 上传upload_dir目录下的zip文件
test/temp%date%.rar 上传到用户目录下并且以“temp+当前日期” 对上传文件重命名
最后是删除本地文件
@echo off
echo open 192.168.1.1 21 >> temp.txt
echo user username password>> temp.txt
echo bin >> temp.txt
echo put "C:\Documents and Settings\user\桌面\patch\upload_dir\1.rar" "test/temp%date%.rar" >> temp.txt
echo bye >> temp.txt
ftp -n -s:"temp.txt"
del /q C:\Documents and Settings\user\桌面\patch\upload_dir\1.rar
del /q temp.txt
pause
实例
本机为Windows,服务器为Linux且其用户名为root,密码为1111。创建一个test.bat文件和一个128.txt文件。需要传的文件test(二进制bin文件)放在相同目录下,双击test.bat则可以自动FTP上传文件到服务器。
test.bat内容为:
ftp -s:128.txt
128.txt内容为:
open 128.0.0.28
root
root
cd /tmp
bin //bin文件传输模式
mput test //or put test or send test
<空一行>
bye
dos下ftp上传下载文件
cmd下
c:/> ftp ip
接下来服务器询问你用户名和口令,待认证通过即可。
开始上传文件,比如说我们要把本地的d:/index.html传至服务器的根目录中,可以这么键入:
ftp> put d:/index.html (回车)
当屏幕提示你已经传输完毕,可以打入相关命令查看一番:
ftp> dir (回车)
刚刚讲的是上传,现在来看下载。假设要把服务器/images目录中的所有.jpg文件传至本机中,按以下指令操作:
ftp> cd images(回车) [注:进入/images目录]
ftp> mget *.jpg ← 也可以mget *.* d: 也就是下载到您的指定目录 上传与下载工作完毕,可以运行bye中断连接。
ftp> bye(回车)
最后为了方便大家记忆,总结一下常用的FTP命令:
1. open:与服务器相连接;
2. send(put):上传文件; 3. get:下载文件; 4. mget:下载多个文件; 5. cd:切换目录; 6. dir:查看当前目录下的文件; 7. del:删除文件; 8. bye:中断与服务器的连接。 |