Include credentials of shared folder in WinSCP script file

被刻印的时光 ゝ 提交于 2019-12-08 05:50:54

问题


In order to access a remote shared folder, I need to indicate the username and password. However, I have no idea where to put it in my WinSCP code.

open ftps://ftpuser:password@hostname/ -explicit -certificate="key"
cd Results
lcd \\networkname\sharedfolder\folder\ 
put *

This produces an error which is:

Error changing directory to '...'.

Any idea? Thanks


回答1:


The error "Error changing directory", which you are getting is most probably caused by the lcd command. In Windows, the current working directory cannot be an UNC path (the \\networkname).

Instead of changing the current working directory, upload the file using a full path:

open ftps://ftpuser:password@hostname/ -explicit -certificate="key"
cd Results
put \\networkname\sharedfolder\folder\*

However if you actually need credentials for accessing the UNC path (the \\networkname), you have to authenticate prior to running the WinSCP script.

The batch file will be like:

net use \\networkname\sharedfolder password /user:domain\username /savecred /p:yes

winscp.com /script=... /log=...

net use \\networkname\sharedfolder /delete

Credits: How to create MAP Drive by batch file.

You still need to use the full path with the put command, instead of the lcd though. Unless you map the UNC path to a drive letter.



来源:https://stackoverflow.com/questions/36853620/include-credentials-of-shared-folder-in-winscp-script-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!