日期:2014-05-17  浏览次数:20821 次

求一个批处理
我要从远程FTP上定时下一个类似cccl20110711.rar 的数据包。。应该怎么写。。。
主要是FTP命令中 用GET 或者 MGET *日期.rar 不知道该如何处理。。

------解决方案--------------------
cmd里echo %date%看下
如果像我的格式是:2011-07-12 星期二

@echo off
echo open 服务器域名或IP地址 > %tmp%\ftp.ini
echo 用户名 >> %tmp%\ftp.ini
echo 密码 >> %tmp%\ftp.ini
echo cd 文件所在目录名 >> %tmp%\ftp.ini
echo get cccl%date:~0,4%%date:~5,2%%date:~8,2%.rar >> %tmp%\ftp.ini
echo bye >> %tmp%\ftp.ini
ftp -s:%tmp%\ftp.ini
del %tmp%\ftp.ini


如果你的时间格式与我不符,则要修改蓝段
------解决方案--------------------
//就是说。。。FTP下。。。没有办法做到直接传参数进去。。
是的

//你这样做等于是回避了这个问题。。。每次取数都先生成一个固定的ftp.ini 文件。。。
你既然学到了FTP无法识别系统环境变量,人家也给出了可行的方法,何来回避?

//我想探讨一下。。。还有没有其他的可能。。做到这一点呢???
一般来说,木有。大都是按照3楼的方法来搞定的
------解决方案--------------------
可以直接在CMD下ftp登录上去
用cd进入远程的目录,用get 文件 本地保存路径 来保存。。
------解决方案--------------------
1.新建down.bat文件,内容如下:
@echo off
@if "%1"=="" goto err
@echo open 服务器域名或IP地址 > c:\ftp.ini
@echo 用户名 >> c:\ftp.ini
@echo 密码 >> c:\ftp.ini
@echo cd 文件所在目录名 >> c:\ftp.ini
@echo get "%1" >> c:\ftp.ini
@echo bye >> c:\ftp.ini
@ftp -s:c:\ftp.ini
@del c:\ftp.ini
@goto end

:err
@echo No File Name Specific!

:end

2.下载cccl20110711.rar 文件时,命令行中执行"down.bat cccl20110711.rar"的方式来下载


C:\>ftp -h

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host]

-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-w:buffersize Overrides the default transfer buffer size of 4096.
host Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.