我的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"
答案 0 :(得分:0)
脚本文件的路径包含空格。因此,您必须将其包装为引号以使其清楚,路径的开始和结束位置。
$argu="$user -pw=$pw -cmdfile=`"$local\sftp.txt`""