如何从PowerShell /批处理文件中的网络路径运行命令

问题描述 投票:1回答:1

基本上我正在尝试运行的是:

cd /d W:\RemoteMirror\ && winscp.com /ini=nul /script=Remote_Mirror_WinSCP.txt

或这个:

cd /d \\fileServer\RemoteMirror\ && winscp.com /ini=nul /script=Remote_Mirror_WinSCP.txt

当然,使用SQL Server,我不能使用UNC路径。但我不知道如何做到这一点。我对PowerShell还不太熟悉,但那是我最好的猜测。

sql-server powershell cmd sql-server-2012 winscp
1个回答
1
投票

UNC路径不能是当前工作目录(这是Windows限制,它与SQL服务器无关)。


正如@lit已经评论过的那样,您可以使用pushd command临时为UNC路径分配驱动器号,并立即将工作目录更改为它。


或者,修改WinSCP脚本不依赖于当前工作目录。

只需在脚本中使用完整的UNC路径,例如:

get "/remote/path/*" "\\fileServer\RemoteMirror\"

另见Using batch file and WinSCP to download files from the FTP server to file server (shared folder)


或者,如果您需要使脚本使用不同的目录,请使用parameterized script

get "/remote/path/*" "%1%\"

并运行它:

winscp.com /ini=nul /script=Remote_Mirror_WinSCP.txt /parameter \\fileServer\RemoteMirror

查看使用parameterized scripts的完整示例。

© www.soinside.com 2019 - 2024. All rights reserved.