Move Files from Multiple Remote Linux Servers to Windows Server

Hi

May I ask what’s the best way to do this please?

I have this so far, which just copies the files.

I actually need to either move them from remote LINUX to local WINDOWS or copy to Windows then delete from remote LINUX servers.

Thanks

Note: some of these commands are commented out.


# INITIALLY: run the line below to create a text file 'SecureString.txt' containing the secure string of the myusername password you enter in the prompt 
# Read-Host "Enter Password" -AsSecureString |  ConvertFrom-SecureString | Out-File "SecureString.txt"

# Read the encrypted password
$encrypted  = Get-Content ".\SecureString.txt" | ConvertTo-SecureString

# Create the credential/login
$credential = New-Object System.Management.Automation.PsCredential('myusername', $encrypted)

# Variables
$serverName   = "MYLINUXSERVER"
$remoteFolder = "/app/dir1/dir2/dir3/log/AccessLog"
$localFolder  = "D:\dir1\MYLINUXSERVER\dir3"
$fileName     = "access_????-??-??.??.log"

# Copy the file from (remote) Linux server to this Windows server
#$session = New-SFTPSession -ComputerName $serverName -Credential $credential
# Cant use wildcards, not suitable
#Get-SFTPFile -SFTPSession $session -RemoteFile "$($remoteFolder)/$($fileName)" -LocalPath $localFolder

# These may require an SSH public key to be set up
#Get-SCPFile -ComputerName $serverName -Credential $credential -RemoteFile "$($remoteFolder)/$($fileName)" -LocalFile $localFolder
#pscp -v "myusername@$($serverName):$($remoteFile)/$($fileName)" "$($localFile)"

# Copy the file from (remote) Linux to Windows
# Note: also copies todays files which I don't really want: access_yyyy-mm-dd.hh.log
Get-SCPFolder -ComputerName $serverName -Credential $credential -RemoteFolder $remoteFolder -LocalFolder $localFolder

# Error: Connecting to remote server failed: Logon failure. This does not work for LINUX servers apparently.
#Invoke-Command -ComputerName $serverName -Credential $credential -ScriptBlock {Remove-Item -Path "$($remoteFile)/$($fileName)" -Verbose}

Anyone ideas please?

Any help appreciated.

Hi, welcome to the forum :wave:

I think it’s a bit tricky for people to help you based on what you’ve posted. So much of it is commented out, it’s not clear what commands you’re actually running and which one is causing the error.

You also have a mixture of PowerShell and PuTTY in there or is pscp an alias?

If you forget about copying for a minute, are you able to SSH to the server using New-SSHSession?

1 Like