VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

SCP without entering password

Hi,

Is there a way to specify password in the script for SCP to copy VMs from one ESXi

​scp -r root@192.168.1.100:/vmfs/volumes/VNX_DS_Uni_Dev_Vol/app42/ .

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I was able to replicate that timeout error you are getting.

The following seems to avoid that error and works for me.

Note that I use a timeout value in 2 locations!

$lines = 'cd /vmfs/volumes/FASLUN01',

         'scp -rv -o ConnectTimeout=3600 /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .',

         'ls -l /vmfs/volumes/FASLUN01'

$cmdSub = $lines -join ';'


$Credentials = Get-Credential

$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey

Invoke-SSHCommand -SSHSession $session -Command $cmdSub -TimeOut 3600

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
22 Replies
LucD
Leadership
Leadership
Jump to solution

Which script are you talking about?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I dont have any script currently, I am manually performing the migration by logging into esxi host.

Is there a way to login to esxi host through script and execute this command

scp -r root@192.168.1.100:/vmfs/volumes/VNX_DS_Uni_Dev_Vol/app42/ .

Please help.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, I would suggest to use the Posh-SSH module.

See also my Use Posh-SSH instead of PuTTY post.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks for your suggestion.

I have arrived to the below script

$esx = '192.168.10.10'

$Username = 'root'

$password = 'password'

$secpasswd = ConvertTo-SecureString -AsPlainText $password -Force

$Credentials = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)

$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'

$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'

$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey

Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output

Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output

The above scripts runs and I get a prompt. the issue, how do I know the status of copy ?

please help...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can't you just do an ls after the copy?

$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'

$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'

$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'


$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey


Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output

Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output

Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I think, copying is not happening.  I made the below changes

$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'

$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'

$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'

$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output

$res

Output Error

scp: ambiguous target

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If I understand your command correctly, you are copying a file on the same ESXi node between 2 directories.

Why do you use scp in that case?

Can't you just use 'cp'?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried even copying from different esxi host, still the same error

$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'

$cmdSub2 = 'scp -r root@192.168.1.11:/vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'

$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'

$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output

$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output

$res

Error

scp: ambiguous target

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this.
Each new call to Invoke-SSHCommand is as if you opened a new terminal.

$lines = 'cd /vmfs/volumes/FASLUN01',

              'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'

              'ls -l /vmfs/volumes/FASLUN01'

$cmdSub = $lines -join ';'


$Credentials = Get-Credential

$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey

Invoke-SSHCommand -SSHSession $session -Command $cmdSub


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

The above works but I am getting the below error. Also how can get the status of the copy like 10% complete, 20% complete etc.....

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like you might be hitting a timeout.

Two things to try:

  • do the same, but with a much smaller file (just to check that the concept works)
  • use the TimeOut parameter on the Invoke-SshCommand cmdlet. The value is in seconds, and there is apparently no default value


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried with the small file, it works without any issues but for bigger files still I am not able to see the status of the copy (% of copy complete)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try specifying a TimeOut value?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

yes, but still the same. attached the file.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What did you specify as the TimeOut value?

My previous comment was incorrect, the default is 3600 seconds.
Does that copy take more than 1 hour?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

the default for 60, I changed to 3600, but still the same. I changed in two places from default 60 to 3600

0 Kudos
LucD
Leadership
Leadership
Jump to solution

How big is that ISO file?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

ISO file is around 3 GB and takes around 7 - 8 mins to copy

even though, it says timeout error, copy is in progress at the backend and after sometime I see file was copied.

how can I avoid that timeout error ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I was able to replicate that timeout error you are getting.

The following seems to avoid that error and works for me.

Note that I use a timeout value in 2 locations!

$lines = 'cd /vmfs/volumes/FASLUN01',

         'scp -rv -o ConnectTimeout=3600 /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .',

         'ls -l /vmfs/volumes/FASLUN01'

$cmdSub = $lines -join ';'


$Credentials = Get-Credential

$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey

Invoke-SSHCommand -SSHSession $session -Command $cmdSub -TimeOut 3600

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos