使用CMD/FTP创建到今天为止的文件夹&将ftp下载连接到已创建的文件夹中 [英] CMD/FTP to create folder using to today date & connect ftp download into created folder

查看:202
本文介绍了使用CMD/FTP创建到今天为止的文件夹&将ftp下载连接到已创建的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个cmd/FTP命令的新手.我想使用今天的日期在本地目录中创建一个新文件夹,并连接到FTP以将特定文件下载到新创建的文件夹中.如果我在cmd上一一手动键入命令,则没有问题.但是,当我使用批处理文件运行时,我的命令在FTP处停止了.

I'm new to this cmd/FTP command. I would like to create a new folder at my local directory using today's date and connect to FTP to download the specific file to the newly created folder. If I manually type in command one by one at cmd, it has no issue. But when I use a batch file to run, my command stopped at FTP.

setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4"_"job%
mkdir C:\%name%
cd C:\%name%
ftp
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget -i *.*

我确实尝试将命令分为两批; 1.文件夹创建 2. FTP下载,但是下载的文件没有进入我创建的文件夹.下载的文件转到C:\ Document&设置.

I did try to separate my command to two batches; 1. folder creation 2. FTP download but the file downloaded didn't go into the folder I created. the downloaded file went to C:\Document & Settings.

主批处理文件

@echo off
call rename.bat
ftp -i -s:ftp.txt

rename.bat

rename.bat

setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd c:\%name%

ftp.txt

open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget *.*
close

我尝试的另一种方法是使用'!'在FTP环境中时,请创建一个文件夹,然后返回到FTP环境.该方法再次不适用于批处理文件.请帮助

Another method I try is using '!' when in FTP environment, then create a folder then exit back to FTP environment. This method again doesn't work with the batch file. Please help

推荐答案

似乎在启用命令扩展名的情况下,子批处理文件设置的工作目录丢失了,然后该批处理文件退出了.

It seems that with command extensions enabled, the working directory set by a child batch file is lost, then the batch file exits.

我不确定如何解决它,但是您实际上不需要将rename.bat文件作为单独的文件.此主批处理文件" 应该可以工作:

I'm not sure how to solve it, but you actually do not need the rename.bat file to be a separate file. This "main batch file" should work:

@echo off
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd /d c:\%name%
ftp -i "-s:%~dp0\ftp.txt"

还请注意添加到cd/d.否则,从另一个驱动器启动时,您的批处理将无法工作.您还必须使用%~dp0来引用ftp.txt的批处理文件文件夹.在调用ftp时,您已更改为目标目录.

Also note the /d added to cd. Without that your batch will not work when started from another drive. You also have to use %~dp0 to refer to the batch file folder for the ftp.txt. As at the time ftp is called, you have changed to the target directory.

您甚至可能不需要启用命令扩展名.因此,只需删除setlocal enableextensions也可以解决该问题.尽管您仍然需要%~dp0/d.

You possibly do not even need the command extensions to be enabled. So simply removing the setlocal enableextensions might solve the problem too. Though you still need the %~dp0 and /d.

这篇关于使用CMD/FTP创建到今天为止的文件夹&将ftp下载连接到已创建的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆