Skip to content

SFTP upload issue when folder name has a space #23

@harleykin

Description

@harleykin

I'm using your SFTP uploading example here: https://github.com/EvotecIT/Transferetto/blob/master/Examples/Example07-UploadSFTP.ps1 and it works GREAT except when a folder to be uploaded has a space in the folder name.

Example: /uploads/folder/sub folder/* is placed at the root uploads folder, rather than under /uploads/folder/*

(I hope this made sense)

This is the script I used:

$SftpClient = Connect-SFTP -Server 'sftp.server.com' -Username "test.user" -PrivateKey "C:\Path\to\My\Private_key" -Verbose
$ListFiles = Get-ChildItem -LiteralPath "C:\BoxTesting" -Recurse -File
foreach ($File in $ListFiles) {
    $Directory = [io.path]::GetDirectoryName($File.FullName)
    if ($Directory -eq "C:\BoxTesting") {
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "/dataplatform-sftp-bucket-1234567890/$($File.Name)" -AllowOverride
    } else {
        #$RemotePath = "/dataplatform-sftp-bucket-1234567890/$($Directory.Split('\')[-1])/$($File.Name)"
        $RemoteFolder = "/dataplatform-sftp-bucket-1234567890/$($Directory.Split('\')[-1])"
        $List = Get-SFTPList -SftpClient $SftpClient -Path $RemoteFolder -WarningAction SilentlyContinue
        if (-not $List) {
            $SftpClient.CreateDirectory($RemoteFolder)
        }
        Send-SFTPFile -SftpClient $SftpClient -LocalPath $File.FullName -RemotePath "$RemoteFolder/$($File.Name)" -AllowOverride
    }
}
Disconnect-SFTP -SftpClient $SftpClient

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions