batch-file - 如何在远程服务器上创建目录之前检查目录是否存在?
问题描述
我正在File Transfer Protocol
使用工具WinSCP将文件从一台服务器传输到另一台服务器,每种类型的文件都有一个单独的目录来存储,因此在传输之前我必须创建该目录。但是当第二次传输相同类型的文件时,它会失败,因为同名的目录已经存在。
两台服务器都使用Windows 操作系统,所以我正在创建一个批处理文件来传输文件,批处理代码如下:-
@echo off
set user=%1
set type=%2
set input=D:\path\to\files\%user%\%type%\*.*
"WinSCP.com" ^
/log="D:\path\to\log\WinSCP.log" /ini=nul ^
/command ^
"open ftp://users:passwords@127.0.0.1/" ^
"mkdir %user%" ^
"cd %user%" ^
"mkdir %type%" ^
"cd %type%" ^
"put %input%" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
这是WinSCP.log
:-
. 2019-01-29 14:40:28.938 Using FTP protocol.
. 2019-01-29 14:40:28.938 Doing startup conversation with host.
> 2019-01-29 14:40:28.938 PWD
< 2019-01-29 14:40:28.938 257 "/" is the current directory.
. 2019-01-29 14:40:28.938 Getting current directory name.
. 2019-01-29 14:40:28.938 Startup conversation with host finished.
< 2019-01-29 14:40:28.939 Script: Active session: [1] users@127.0.0.1
> 2019-01-29 14:40:28.939 Script: mkdir compo-sucks-a-little
. 2019-01-29 14:40:28.939 Creating directory "compo-sucks-a-little".
> 2019-01-29 14:40:28.939 CWD /
< 2019-01-29 14:40:28.939 250 "/" is the current directory.
> 2019-01-29 14:40:28.939 MKD compo-sucks-a-little
< 2019-01-29 14:40:28.940 550 File exists.
. 2019-01-29 14:40:28.940 Asking user:
. 2019-01-29 14:40:28.940 Error creating folder 'compo-sucks-a-little'. ("File exists.")
< 2019-01-29 14:40:28.940 Script: Error creating folder 'compo-sucks-a-little'.
< 2019-01-29 14:40:28.940 Script: File exists.
. 2019-01-29 14:40:28.941 Script: Failed
. 2019-01-29 14:40:28.941 Script: Exit code: 1
. 2019-01-29 14:40:28.941 Disconnected from server
我想在创建目录之前检查目录是否已经存在。
解决方案
推荐阅读
- node.js - SyntaxError: Unexpected token / in .... while compile ejs | Node.js 与 MongoDB
- vba - 基于查询的特定列表框的空白列不被识别为空或空
- javascript - 将文件写入文件系统,然后在 Express 中下载
- python-3.x - pandas 两个值相乘结果的总和
- google-sheets-formula - 如何在 Query 函数中添加 Count 或 Countif 之类的条件来限制?
- java - JavaFX:不管我写的代码,它总是出现一个空白的“hello word”GUI
- javascript - 如何通过 Props 提取 Route Params
- flutter - 颤振:找不到包“build_runner”
- javascript - 如何对数组中大于 150 的元素求和?
- java - 返回新字符串(密码);有人可以解释一下,这是如何返回 String 的吗?