我正在尝试使用批处理命令文件将文件上传到FTP服务器。我的代码使用WinSCP,如下所示:
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Program Files (x86)\WinSCP\WinSCP.log" /ini=nul ^
/command ^
"open ftp://user:pass@ftp.website.org/" ^
"lcd %cd%" ^
"cd /incoming/data" ^
"put %~dp0file.txt" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
日志显示以下内容:
> 2020-10-14 15:16:39.044 Script: put C:\Users\me\sharepoint - library folder\FTP\file.txt
. 2020-10-14 15:16:39.047 Copying 4 files/directories to remote directory "/incoming/data" - total size: 0
. 2020-10-14 15:16:39.047 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: folder\FTP\file.txt
. 2020-10-14 15:16:39.047 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; EncryptNewFiles: Yes; ExcludeHiddenFiles: No; ExcludeEmptyDirectories: No; InclM: ; ResumeL: 0
. 2020-10-14 15:16:39.047 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
* 2020-10-14 15:16:39.048 (EOSError) System Error. Code: 2.
* 2020-10-14 15:16:39.048 The system cannot find the file specified
我期望put %~dp0file.txt
提供我要上传的文件的完整路径,看起来它可以从日志中正确获取它,但是我不知道为什么它要发送4个文件或为什么找不到指定的文件。我应该注意,路径(文件夹/ ftp)实际上更长,完整路径为102个字符。该路径包含空格和一个破折号。
答案 0 :(得分:2)
您的路径包含空格,因此必须为wrapped to double quotes:
"put ""%~dp0file.txt""" ^
lcd
也是如此。但是由于使用lcd
没有任何意义,因此,如果您仍然在put
命令中使用绝对路径,则可以完全删除lcd
。