Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a SCP alternative for PowerShell?

Tags:

I need to write a script that transfers files from a folder onto another server (Linux), but the script that's transferring files is on windows, and I was wondering if there was an alternative to scp for PowerShell (or if there was another way of doing this)

like image 895
Saad Avatar asked Aug 20 '13 20:08

Saad


People also ask

Does PowerShell have SCP?

By default, the PowerShell Server does not allow SCP connections. This is easily enabled in the server interface using the following steps: On the Connection tab simply check the box that says “Enable Secure Copy Protocol (SCP) Support”. Then click Save Changes and Restart to restart the server with this change.

What can I use instead of SCP?

SFTP is widely considered the successor of SCP. It still runs on top of SSH for transport-layer security and doesn't require setting up access separately. It can give you a custom interactive prompt for exploring the remote filesystem or you can script with a pre-written series of commands.

Is SCP available on Windows?

Windows operating systemsMicrosoft Windows does not include an SCP client, so you must download one first. A2 Hosting recommends PSCP, a free program that you can download here. PSCP is part of the PuTTY tool suite for Windows.

Does SCP work on Windows CMD?

You can run SCP on Windows via PuTTY. Use the SCP command via the Windows command line interface. You should start each command line with pscp -scp.


2 Answers

There is a handy little tool that comes with Putty called pscp.exe that will do this and can be called in powershell easily.

Example below copies from windows to a CentOS box (logging in as the usercode "bill") and you use the -pw switch in pscp to pass in a password (otherwise the command window that is spawned will prompt for the Linux password):

Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw password C:\Document.rtf [email protected]:/home/bill/")  

PuTTY Secure Copy client
Release 0.62
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -p        preserve file attributes
  -q        quiet, don't show statistics
  -r        copy directories recursively
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -P port   connect to specified port
  -l user   connect with specified username
  -pw passw login with specified password
  -1 -2     force use of particular SSH protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -batch    disable all interactive prompts
  -unsafe   allow server-side wildcards (DANGEROUS)
  -sftp     force use of SFTP protocol
  -scp      force use of SCP protocol
like image 193
Graham Gold Avatar answered Sep 19 '22 05:09

Graham Gold


pscp.exe is a viable option, but I have been using a library from Rebex for a couple years now for SFTP and FTPS transfers in both C# apps and PowerShell scripts with great success. Their package also includes an SCP object but I haven't personally used it.

It does cost money vs. pscp being free. Before selecting the Rebex package, I had considered going the PuTTY route but my team decided that having a library we could easily roll into any app/script was worthwhile in the long term.

like image 27
alroc Avatar answered Sep 21 '22 05:09

alroc