简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM