DOS 脚本 tp 从远程服务器将文件复制到本地文件夹
我需要编写一个 dos 脚本,该脚本首先从远程服务器通过 FTP 传输到本地目录,然后将这些文件复制到本地计算机中的另一个文件夹。第二步背后的原因是目标文件夹路径取决于系统处理器是32位还是64位。
我有两个独立的脚本,现在运行良好。但是当我将它们放在一个脚本中时,ftp 命令提示符失败了。这是我正在使用的脚本 -
@echo off
:MAIN
SETLOCAL ENABLEDELAYEDEXPANSION
set winver=%PROCESSOR_ARCHITECTURE%
rmdir c:\batch\temp
mkdir c:\batch\temp
goto :ftpbegin
:ftpbegin
@ftp -i -s:"%~f0"&GOTO:EOF
open x.y.z.a
<userid>
<password>
!:-----FTP commands here -----
lcd C:\batch\temp
cd CGServices\Uploads
binary
mget "*.psl"
mget "*.PST"
mget "*.psy"
get abc.ini
get def.pmd
disconnect
bye
:eof
exit /b
:findwin
if %winver% ==x86 (goto :copywin32) else (goto :copywin64)
:copywin32
echo "inside copywin32"
<do the copy files here>
:copywin64
<do copy files here>
exit /b 0
但是,ftp 脚本似乎在执行程序的第二部分时导致中断,因为它在 ftp 提示符中循环调用该程序。因此,FTP 提示符下的任何 dos 命令都不会被翻译。
非常感谢任何有关如何在单个脚本中实现此目的的帮助。
谢谢, 桑德斯
I need to write a single dos script which will first FTP from a remote server to my local directory and then will copy these files to another folder within the local machine. The reason behind the second step is that the destination folder path is based on whether the SYSTEM Processor of 32-bit or 64-bit.
I have two separate scripts which are working fine now. But when I am putting them together in a single script, it is failing with the ftp command prompt. Here is the script which I am using -
@echo off
:MAIN
SETLOCAL ENABLEDELAYEDEXPANSION
set winver=%PROCESSOR_ARCHITECTURE%
rmdir c:\batch\temp
mkdir c:\batch\temp
goto :ftpbegin
:ftpbegin
@ftp -i -s:"%~f0"&GOTO:EOF
open x.y.z.a
<userid>
<password>
!:-----FTP commands here -----
lcd C:\batch\temp
cd CGServices\Uploads
binary
mget "*.psl"
mget "*.PST"
mget "*.psy"
get abc.ini
get def.pmd
disconnect
bye
:eof
exit /b
:findwin
if %winver% ==x86 (goto :copywin32) else (goto :copywin64)
:copywin32
echo "inside copywin32"
<do the copy files here>
:copywin64
<do copy files here>
exit /b 0
However, the ftp script seems to cause a break while executing the second part of my program since it is calling the program in a loop in ftp prompt. So, none of the dos commands are translated on FTP prompt.
Any help on how to achieve this in a single script for this is highly appreciated.
thanks,
Sanders
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FTP 命令 AFAIK 无法在不从外部文件读取 ftp 命令的情况下处理来自命令行的命令。我通常下载 Windows 版本的 wget,它对我们来说效果很好,也许你想看看。
这是 wget 的手册 http://www.editcorp.com/Personal /Lars_Appel/wget/v1/wget_7.html
例如
The FTP command AFAIK cannot process the commands from the command line without reading the ftp commands from an external file. I usually download a windows version of wget, and it works well for us, perhaps you would like to have a look at that.
Here is the manual for wget http://www.editcorp.com/Personal/Lars_Appel/wget/v1/wget_7.html
for example
调用 ftp 命令后,您告诉脚本跳转到 ':EOF'。您不能使用
:EOF
标签在批处理文件内跳转。Goto :EOF
基本上意味着“跳转到文件末尾”,这通常与调用exit /b
相同。您还可以从子例程内部调用goto :EOF
。在这种情况下,它的意思是“这是子例程的结束”。有关详细信息,请参阅goto /?
和call /?
因为在 ftp.exe 中,您将 .bat 文件用作 ftp 命令脚本,所以
之前的所有行>open xyza
会给您无效命令
消息,因此最好尽量减少 FTP 命令块之前的行数。您的脚本应如下所示:
After invoking
ftp
command you tell your script to jump to ':EOF'. You can not use:EOF
label for jumping inside a batch file.Goto :EOF
basically means "jump to the end of the file", which is generally the same as callingexit /b
. You can also callgoto :EOF
from inside a subroutine. In this case it mean "this is the end of the subroutine". For more info, seegoto /?
andcall /?
Because in ftp.exe you are using your .bat file as a ftp command script, all the lines before
open x.y.z.a
will give youinvalid command
messages, so it would be good to minimize the number of lines before FTP command block.Your script should look like this: