Exception calling “UploadFile” with “2” argument(s): “The Content-Type header cannot be set to a multipart type for this request.”
i'm working on powershell script , getting above error, not understanding. appreciated!
$down = "c:\script\log\down-hosts.log" $computers = get-content "c:\script\list\computers.txt" $sourcefilename = "source_file.csv" #ftp server $ftp = "sftp://servername" $user = "user" $pass = "pass" $webclient = new-object system.net.webclient $webclient.credentials = new-object system.net.networkcredential($user,$pass) # create empty log file down hosts (overwrite if exists) new-item $down -type file -force foreach ($computer in $computers) { if ( test-connection -computername $computer -count 1 -erroraction silentlycontinue ) { write-host "$computer up" write-host "uploading \\$computer\c$\ups csv exports\$sourcefile..." $sourcefilepath = "\\$computer\c$\ups csv exports" $uri = new-object system.uri($ftp+$computer+"_"+$sourcefilename) $webclient.uploadfile($uri,$sourcefilepath+"/"+$sourcefilename) if($? -eq $true) { write-host "$ftp$sourcefilename ok" remove-item $sourcefilepath"\"$sourcefilename } } else { write-host "$computer down" "$computer down" | out-file $down -append } }
in script, using ftp move file ftp directory , think partly problem. instead of using ftp, use copy/paste/move file due ftp server directory being on same network/domain computer running script. if have has modification script, of great newbie when comes powershell.
thanks!
russ, mcse
copy-item or move-item far easier managing ftp connection. i didn't test there might typos should pretty close, gotta run, luck!
$down = "c:\script\log\down-hosts.log" $computers = get-content "c:\script\list\computers.txt" $targetpath = "\\servername\sharename\path" $sourcefilename = "source_file.csv" foreach ($computer in $computers) { if ( test-connection -computername $computer -count 1 -erroraction silentlycontinue ) { $sourcefilepath = "\\$computer\c$\ups csv exports\$sourcefilename" write-host "$computer up" write-host "copying $sourcefilepath ..." try { if (test-path $sourcefilepath) { move-item $sourcefilepath "$targetpath\$computer`_$sourcefilename" -force } else { throw "$sourcefilepath not exist" } } catch { write-host "error: $($error[0].exception.message)" } } else { write-host "$computer down" "$computer down" | out-file $down -append } }
i hope post has helped!
Windows Server > Windows PowerShell
Comments
Post a Comment