[英]SFTPC error “Unexpected command parameter: -cmdfile” when calling from PowerShell script
我的PowerShell腳本有點麻煩。 我寫這篇文章的目的是將.txt
文件上傳到SFTP到SFTP根目錄下名為IN
的文件夾中。
我收到SFTPC錯誤。 我猜我遇到了麻煩
$argu="$user -pw=$pw -cmdfile=$local\sftp.txt"
它還將我的文件夾從$Local
移到$destination
,我猜這是因為SFTPC無法正常工作?
我是PowerShell的新手,我無可救葯了。
這是下面的錯誤。
ERROR: Unexpected command parameter: -cmdfile=C:\Users\bendonac\Script.
USAGE:
sftpc [username@]host[:port] OR -profile=file [-host=host] [-port=port] [-
obfs=y|n] [-obfsKw=keyword] [-spn=SPN] [-sspi=y|n] [-sspiDlg=y|n]
和腳本:
#PowerShell script to transfer files
#Set file list to null
$file_list=@()
$sftp_put=@()
#Set SFTP user and hostname
$user="username@xxx.xxx.xxx.xx"
#Set SFTP Password
$pw='Secure Password'
#Set SFTP executable name
$sftp_prog="sftpc.exe "
#Set local folder
$local="C:\Users\ben\Script test"
#Set SFTP Arguments
$argu="$user -pw=$pw -cmdfile=$local\sftp.txt"
#Build SFTP command line
$final=$sftp_prog+$argu
#Set target location
$destination="UNC PATH"
$files=get-childitem -filter *.txt $destination
foreach ($object1 in $files) {
$file_list+="put "+$object1.fullname + "\in"
}
$file_list | out-file $local\sftp.txt
#*********Stage 2 upload to SFTP Server *********
set-location "C:\Program Files\Bitvise Tunnelier"
$sftp="sftpc.exe "
$path="sftp_get_manifest.txt"
$argu="$user -pw=$pw -cmdfile=$local\sftp.txt"
#$final= $sftp+$argu
cmd /c $final
try{
move-item -path $local -destination $destination -force
}
Catch {
$thereisanerror = ‘true’
}
#Remove old sftp script if it exists
if (test-path $local\sftp.txt) {remove-item $local\sftp.txt -force}
#Check last exit code for any SFTP errors
Error" -body "The SFTP download script has failed with an $lastexitcode
error. please investigate." -from "Ben@domain.com" -smtpserver
"cas.domain.internal"
腳本文件的路徑包含空格。 因此,您必須將其用引號引起來,以便清楚地說明路徑的起點和終點。
$argu="$user -pw=$pw -cmdfile=`"$local\sftp.txt`""
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.