- 1 year ago
Transfer file from Windows to Linux without using 3rd party software and using Shell.Application only
To transfer a file from Windows to Linux without using third-party software and using the Shell.Application
object in PowerShell, you can utilize the CopyHere
method to copy the file to a network location accessible by the Linux machine. Here's an example:
powershell$sourceFilePath = "C:\path\to\file.txt"
$destinationFolderPath = "\\LinuxMachine\SharedFolder"
$shell = New-Object -ComObject Shell.Application
$destinationFolder = $shell.NameSpace($destinationFolderPath)
$sourceFile = $shell.NameSpace($sourceFilePath)
$destinationFolder.CopyHere($sourceFile.Items(), 20)
In the example above, replace "C:\path\to\file.txt"
with the path of the file you want to transfer and "\\LinuxMachine\SharedFolder"
with the network path of the shared folder on the Linux machine.
The CopyHere
method is used to copy the file from the source folder to the destination folder. The second parameter 20
is an optional flag to indicate the copy operation should be asynchronous.
Please note that for this method to work, you need to have appropriate file sharing and network access permissions set up on the Linux machine. The Linux machine should also be reachable from the Windows machine over the network.
Keep in mind that using third-party software or native Linux file transfer methods like scp
or rsync
may offer more reliable and efficient ways to transfer files between Windows and Linux machines.