# Copy file from one server to another remotely?

#### TaSMania

Anyone has a good program script to copy files from one server to another remotely?
I'm trying to script so that I dont have to manually logon to both servers and copy and paste.
I'd tried Powershell using this but per Google search it seems that -tosession does not work.

$session01 = New-PSSession -Credential$myuserID $mypassword -ComputerName$server001
$session02 = New-PSSession -Credential$myuserID $mypassword -ComputerName$server002
Copy-Item -Path "C:\temp\test.txt" -FromSession $session01 -Destination "C:\Temp\test.txt" -ToSession$session02

dont worry about the -credential I will add this later. I just want it to copy first.
$Pass = cat PSCred.txt | ConvertTo-SecureString$PSCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pass

#### TaSMania

copy-item didn't work so i'd tried invoke-command and it doesn't like my credential. Could it be because of my special character?

$User="myusername"$Pass="mypassword contains many special characters"
$session02 = New-PSSession -Credential$myuserID $mypassword -ComputerName$server002
$mycopy = {Copy-Item -Path "C:\temp\test.txt" -Destination "C:\Temp\text.txt" -ToSession$session02}
Invoke-Command -ComputerName server001 -Credential $User,$Pass -ScriptBlock $mycopy ### Advertise at ADSM.ORG If you are reading this, so are your potential customer. Advertise at ADSM.ORG right now. ### UpCloud high performance VPS at$5/month

Get started with \$25 in credits on Cloud Servers. You must use link below to receive the credit. Use the promo to get upto 5 month of FREE Linux VPS.