2016-11-16 10 views
0

나는 PowerShell 스크립트WinSCP 명령으로 실행되는 PowerShell 스크립트에서 매개 변수를 전달하는 방법은 무엇입니까?

cd "C:\Program Files (x86)\WinSCP" 
. .\WinSCP.exe /console /script="L:\Work\SAS Data\FTP\local2remote.txt" /log=log.txt 

그것은 WinSCP에 명령 파일을 호출에게이

option batch on 
open ftp://user:[email protected] -passive=on 
lcd "J:\Work\SAS Data\Roman\Lists" 
put target.csv 
exit 
I 변환 할

다음 PowerShell 스크립트에서 매개 변수에 "J \ 일 \ SAS 데이터 \ 로마 \ 목록을" 여기서 매개 변수는 txt 파일에서 전달 될 수 있습니다. target.csv 파일도 마찬가지입니다. 어떤 도움을 주셔서 감사합니다.

+0

[PowerShell 스크립트] (https://winscp.net/eng/docs/library_powershell)에서 [WinSCP .NET 어셈블리] (https://winscp.net/eng/docs/library)를 사용하는 것이 좋습니다. –

답변

3

가장 쉬운 방법 (임시 스크립트 파일을 작성 포함하지 않는 한)은 WinSCP에 대한 /command로 전환하는 것입니다 : 이제

# You don't need the . operator to run external programs 
.\WinSCP.exe /console /log=log.txt /command ` 
    'open ftp://user:[email protected] -passive=on' ` 
    'lcd "J:\Work\SAS Data\Roman\Lists"' ` 
    'put target.csv' ` 
    'exit' 

당신은 훨씬 쉽게 시간이 스크립트 매개 변수를 통합 있습니다

param([string] $Path, [string] $FileName) 

& 'C:\Program Files (x86)\WinSCP\WinSCP.exe' /console /log=log.txt /command ` 
    'open ftp://user:[email protected] -passive=on' ` 
    "lcd `"$Path`"" ` 
    "put `"$FileName`"" ` 
    'exit' 

그러나 물론 는 여전히 명령 파일을 작성하고 전달합니다

+0

신속한 방법을 이용해 주셔서 감사합니다. 그러나 두 번째 스크립트에서 다음과 같은 오류가 발생합니다. 디렉토리를 $ Path로 변경하는 중 오류가 발생했습니다. –

+0

WinSCP가받는 명령에'$ Path'가 나타나지 않아야합니다. 혹시 큰 따옴표 대신 작은 따옴표를 사용 했습니까? – Joey

+0

그게 전부 야. 고마워 ~ 조이! –