Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP upload issue when folder name has a space #23

Open
harleykin opened this issue Nov 17, 2022 · 7 comments
Open

SFTP upload issue when folder name has a space #23

harleykin opened this issue Nov 17, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@harleykin
Copy link

harleykin commented Nov 17, 2022

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
@harleykin
Copy link
Author

harleykin commented Nov 17, 2022

Here's one of the outputs (sanitized):

Action     : UploadFile
Status     : True
LocalPath  : C:\BoxTesting\Long_Path_Name\z_Archive_YYYY-1234\weekly upload\Very Long Filename with Spaces.txt
RemotePath : /dataplatform-sftp-bucket-1234567890/weekly upload/Very Long Filename with Spaces.txt
Message    : 

@PrzemyslawKlys
Copy link
Member

Are you saying the Send-SFTPFile is unable to support filename with spaces and when it sees one it puts it in wrong folder or are you talking about my example which just shows some functionality, but not really tested for such scenario.

@harleykin
Copy link
Author

I'm saying I think the issue is directory names with spaces, but it could also be I am not using your module correctly. Hence why I was using your example. I could be wrong on both things, as I was wrong on other issues I asked you about. :)

@harleykin
Copy link
Author

Good morning/afternoon! Looking back over the example, its logic looks like it should be doing exactly what I want. But there's an error somewhere. Ideally, I just need to upload files from a local drive to an SFTP, skipping any existing files, creating new directories if they don't already exist, and writing any new files. Your example looks to be doing just that, but something is off somewhere.

@PrzemyslawKlys
Copy link
Member

PrzemyslawKlys commented Nov 21, 2022

I need to do a deeper dive an maybe write something custom. I don't think this fully works to transfer folder with all its files to server the same way it's implemented in FTP. Just playing with Split and [-1] is probably bad idea and a reason it doesn't work reliably.

@harleykin
Copy link
Author

I appreciate you taking a look. The automation PC I'm setting this up on has WinSCP installed, so I might could get that going as a workaround, but honestly I'd rather use your module. :)

@PrzemyslawKlys
Copy link
Member

Implementing this #24 would probably help, but you could try to use this method directly.

@PrzemyslawKlys PrzemyslawKlys added the enhancement New feature or request label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants