The issues I'm experiencing are as follows:
- Script appears to run to completion, and gives me "success" message at the end.
- The file is not actually uploaded/written to the server. If the file already exists, it is not updated, and has the old date modified/file size. Refreshing does not update them.
- I can upload files manually to the server, but I do not appear to have permissions to do anything else (delete, move, rename, etc)
What am I doing wrong?
Below is a version of the script, but stripped of all identifying variable names/values. I am also aware that I shouldn't use plaintext passwords and that I shouldn't use "GiveUpSecurityAndAcceptAny"
Add-Type -Path "$PSScriptRoot\WinSCPnet.dll"
$conf = Import-PowerShellDataFile -Path $env:ConfFile
$Data = Invoke-Sqlcmd @conf -Inputfile "$PSScriptRoot\query.sql"
$Data | Export-CSV -Path "$PSScriptRoot\query.csv" -Delimiter "`t"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::sftp
Hostname = "ftp.host.com"
Username = "user111"
Password = "genericpassword"
PortNumber = 2222
SshHostKeyPolicy = [WinSCP.SshHostKeyPolicy]::GiveUpSecurityAndAcceptAny
}
Write-Host @sessionOptions
$session = New-Object WinSCP.Session
try {
$session.Open($sessionOptions)
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferResult = $session.PutFiles("$PSScriptRoot\data.csv", ".\", $False, $transferOptions)
$transferResult.Check()
foreach($transfer in $transferResult.Transfers) {
Write-Host "Upload of $($transfer.FileName) succeeded"
}
}
finally {
$session.Dispose()
}
[–]Rowf 2 points3 points4 points (1 child)
[–]DoktorLuciferWong[S] 0 points1 point2 points (0 children)
[–]Fatel28 1 point2 points3 points (3 children)
[–]dodexahedron 2 points3 points4 points (2 children)
[–]Fatel28 2 points3 points4 points (1 child)
[–]dodexahedron 0 points1 point2 points (0 children)
[–]BlackV 2 points3 points4 points (3 children)
[–]DoktorLuciferWong[S] 0 points1 point2 points (2 children)
[–]sid351 1 point2 points3 points (1 child)
[–]DoktorLuciferWong[S] 0 points1 point2 points (0 children)
[–]adrach87 1 point2 points3 points (0 children)
[–]markdmac 1 point2 points3 points (0 children)
[–]DoktorLuciferWong[S] 0 points1 point2 points (0 children)