Automation - download all

Advertisement

bloodclot
Joined:
Posts:
1
Location:
Ca

Automation - download all

Trying to just download all files from the root (/) of the host to a drive (google - g drive).

I couldn't get it going to download to the local, it came back and said it succeeded but nothing was there?
try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "test.test.com"
        UserName = "userabc"
        Password = "passabc"
        SshHostKeyFingerprint = "ssh-rsa 2048 P0rBKJMYf1man8NTYvBftJUs5EdvpSyJGSE/S+SxVy4="
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Download files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        $transferResult =
            $session.GetFiles("/*", "f:\my drive\sftp", $False, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host "Download of $($transfer.FileName) succeeded"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,949
Location:
Prague, Czechia

Re: Automation - download all

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

In any case, you are probably missing a backslash in "f:\my drive\sftp\"
See https://winscp.net/eng/docs/library_session_getfiles#localpath

Reply with quote

Advertisement

You can post new topics in this forum