Posh-SSH
Posh-SSH copied to clipboard
Set-SCPItem for a directory does not support unregular characters
Trying to send a whole directory using Set-SCPItem that contains unregluar characters in its name leads to what seems like a locked terminal and nothing happens. I haven't investigated this deeply (maybe the same goes for regular files as well) but a command like this:
>> Set-SCPItem -ComputerName computername -Path .\Folder(Name)\ -Destination /Upload/ -Verbose
VERBOSE: Using SSH Username and Password authentication for connection.
VERBOSE: ssh-ed25519 Fingerprint for computername: <...mac-adress-or-something>
VERBOSE: Fingerprint matched trusted ssh-ed25519 fingerprint for host computername
VERBOSE: Connection successful
VERBOSE: Uploading: C:\Users\User\Folder(Name)\
VERBOSE: Destination: /MUSIC/Interplay/Folder(Name)
This will just hang forever (at least over night 😅) and cant be interupted with ctrl+c. I'm gussing it has to do with some path-parsing on the destination side as ( needs to be escaped 🤔 ( on a *unix machine
As a sidenote; if one tries to send a directory, and a directory with the same name doesn't exist on the Destination, one would get a
>> Set-SCPItem -ComputerName computername -Path .\SomeDir\ -Destination /Upload/ -Verbose
(...)
Set-SCPItem: scp: /Upload/SomeDir: No such file or directory
Which is a little counter-intuitive when one tries to send a complete directory, but not a huge problem. Just annoyance 😇
>> Get-Module Posh-SSH
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 3.0.8 Posh-SSH {Get-SCPItem, Get-SFTPItem, Get-SSHHostKey, Get-SSHJsonKnownHost…}`
you may try to use -PathTransformation
parameter
For which part? The sending of directory with unregular characters, or the handling of "no such file or directory"?
(Both?)
the single command you use in your example - Set-SCPItem
:)
I still have this problem and not fix it yet, and I'm trying tying to use Set-SCPItem with for loop to looping on each file on my folder and then copy it into my server.
$files = Get-ChildItem -Path $MyPath -File
foreach ($file in $files) {
$src = Join-Path -Path $MyPath -ChildPath $file.Name
Set-SCPItem -ComputerName $ComputerName -Credential $Credentials -path $src -Destination $Destination -Verbose
}
What special characters are in your case causing it to fail?
What special characters are in your case causing it to fail?
$ComputerName = "MYSERVERIP" $MyPath = "C:\Users\ibrahim\Desktop\ProjectPublish" $Destination = "/var/www/Project/API" Set-SCPItem -ComputerName $ComputerName -Credential $Credentials -path $MyPath -Destination $Destination -Verbose
the connection and handshake work well but the upload start:
VERBOSE: Uploading: C:\Users\ibrahim\ProjectPublish
VERBOSE: Destination: /var/www/Project/API/ProjectPublish
and that's wrong because ProjectPublish is not exist on my server it's a folder i use to store my project publish result on my device
what i want is to copy all files inside ProjectPublish folder into this path: /var/www/Project/API/ on my server
the conclusion is why my local folder ProjectPublish concat with the Destination and became like this: /var/www/Project/API/ProjectPublish
If you specify a directory it will copy the directory with its name as is to the specified path. It is behaving as expected. If you want to upload each file in the directory individually then you will need a loop to upload each to the root of the target path. SFTP is a better option since you will mot have to establish a tear down a connection for each file