Home > other >  Upload to S3 with WinSCP .NET PowerShell script fails with "Specify target bucket"
Upload to S3 with WinSCP .NET PowerShell script fails with "Specify target bucket"

Time:01-16

I have a PowerShell script to put a local file up to an S3 bucket. However, it is failing:

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::S3
    HostName = "XXX.s3.amazonaws.com"
    UserName = "AAAA"
    Password = "BBB"
}

$session = New-Object WinSCP.Session

try
{
    $session.SessionLogPath = "C:\Temp\Training DB\log.txt"
    # Connect
    $session.Open($sessionOptions)

    $session.PutFiles("C:\path\Training_Employees.csv", "./Training_Employees.csv")
}
finally
{
    $session.Dispose()
}

In the log it looks like my problem is target bucket, but can't figure out how to specify to work:

. 2023-01-14 09:51:52.379 ssl: Shutdown state: not sent | not received.
. 2023-01-14 09:51:52.379 ssl: Sending closure.
. 2023-01-14 09:51:52.380 sess: Connection closed.
. 2023-01-14 09:51:52.380 Request ends, status 200 class 2xx, error line:
. 2023-01-14 09:51:52.380 200 OK
< 2023-01-14 09:51:52.380 <?xml version="1.0" encoding="UTF-8"?>
< 2023-01-14 09:51:52.380 <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">...</ListBucketResult>
. 2023-01-14 09:51:52.380 Request ends.
. 2023-01-14 09:51:52.380 sess: Destroying session.
* 2023-01-14 09:51:52.381 (ECommand) **Copying files to remote side failed.**
* 2023-01-14 09:51:52.381 Specify target bucket.
< 2023-01-14 09:51:52.381 Script: Copying files to remote side failed.
< 2023-01-14 09:51:52.381 Specify target bucket.
. 2023-01-14 09:51:52.382 Script: Failed
> 2023-01-14 09:51:52.445 Script: exit
. 2023-01-14 09:51:52.445 Script: Exit code: 1

CodePudding user response:

The bucket name must be part of the path.

So something like /bucket/Training_Employees.csv, not ./Training_Employees.csv.

See https://winscp.net/eng/docs/faq_script_vs_gui#paths

  • Related