DOS 脚本 tp 从远程服务器将文件复制到本地文件夹

发布于 2024-12-28 20:23:03 字数 929 浏览 1 评论 0原文

我需要编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜警司 2025-01-04 20:23:03

FTP 命令 AFAIK 无法在不从外部文件读取 ftp 命令的情况下处理来自命令行的命令。我通常下载 Windows 版本的 wget,它对我们来说效果很好,也许你想看看。

这是 wget 的手册 http://www.editcorp.com/Personal /Lars_Appel/wget/v1/wget_7.html

例如

wget ftp://<user>:<password>@server.com/upload/file.ext

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

wget ftp://<user>:<password>@server.com/upload/file.ext
夜吻♂芭芘 2025-01-04 20:23:03

调用 ftp 命令后,您告诉脚本跳转到 ':EOF'。您不能使用 :EOF 标签在批处理文件内跳转。 Goto :EOF 基本上意味着“跳转到文件末尾”,这通常与调用 exit /b 相同。您还可以从子例程内部调用goto :EOF。在这种情况下,它的意思是“这是子例程的结束”。有关详细信息,请参阅 goto /?call /?

因为在 ftp.exe 中,您将 .bat 文件用作 ftp 命令脚本,所以 之前的所有行>open xyza 会给您无效命令 消息,因此最好尽量减少 FTP 命令块之前的行数。

您的脚本应如下所示:

@echo off
goto main

:ftpbegin
@ftp -i -s:"%~f0" & goto ftpend
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

:main
SETLOCAL ENABLEDELAYEDEXPANSION
set winver=%PROCESSOR_ARCHITECTURE%
rmdir c:\batch\temp
mkdir c:\batch\temp
goto ftpbegin

:ftpend
if not "%winver%"=="x86" goto copywin64

REM did not jump, so this is a 32-bit system
echo "inside copywin32"
<do copy files here>
goto finish

:copywin64
echo "inside copywin64"
<do copy files here>

:finish
endlocal

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 calling exit /b. You can also call goto :EOF from inside a subroutine. In this case it mean "this is the end of the subroutine". For more info, see goto /? and call /?

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 you invalid command messages, so it would be good to minimize the number of lines before FTP command block.

Your script should look like this:

@echo off
goto main

:ftpbegin
@ftp -i -s:"%~f0" & goto ftpend
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

:main
SETLOCAL ENABLEDELAYEDEXPANSION
set winver=%PROCESSOR_ARCHITECTURE%
rmdir c:\batch\temp
mkdir c:\batch\temp
goto ftpbegin

:ftpend
if not "%winver%"=="x86" goto copywin64

REM did not jump, so this is a 32-bit system
echo "inside copywin32"
<do copy files here>
goto finish

:copywin64
echo "inside copywin64"
<do copy files here>

:finish
endlocal
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文