Uploaded file via the script not making it to the SFTP server
I wrote a script where I'm trying to SFTP a file from one of our shares to a vendor SFTP server. The script completes without error but my file never arrives on the SFTP server. I would like to log the session to find out where the problem is that I cannot see but I cannot see the log file out on my share either. Any help/direction on why my log file is not getting created would be appreciated.
Here is my code:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Declare variables
$date = Get-Date
$dateStr = $date.ToString("yyyyMMdd")
$fileDirectory = "\\share\apps\CoverageVerifier\"
$filePath = "\\share\apps\CoverageVerifier\cvgver." + $dateStr + ".0101"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Webdav
HostName = "secureftpa.verisk.com"
PortNumber = 443
UserName = "account"
Password = "password"
WebdavSecure = $True
TlsHostCertificateFingerprint = "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
}
$session.SessionLogPath = "\\share\apps\CoverageVerifier\UploadLog.log"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)[/code]
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($filePath, "/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host "Upload of $($transfer.FileName) succeeded"
}
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
finally
{
$session.Dispose()
}
Here is my code:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Declare variables
$date = Get-Date
$dateStr = $date.ToString("yyyyMMdd")
$fileDirectory = "\\share\apps\CoverageVerifier\"
$filePath = "\\share\apps\CoverageVerifier\cvgver." + $dateStr + ".0101"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Webdav
HostName = "secureftpa.verisk.com"
PortNumber = 443
UserName = "account"
Password = "password"
WebdavSecure = $True
TlsHostCertificateFingerprint = "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
}
$session.SessionLogPath = "\\share\apps\CoverageVerifier\UploadLog.log"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)[/code]
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($filePath, "/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host "Upload of $($transfer.FileName) succeeded"
}
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
finally
{
$session.Dispose()
}