23

when calling SCP in PuTTY on my Win7 box, it doesn't let me use C:/, but I also have no idea where on my local machine it will look for files by default. None of program directory or user directory worked. For example, I saved file.txt next to PuTTY.exe, and also in C:\Users\Me but calling SCP file.txt file.txt in PuTTY failed both times with

cp: cannot stat 'file.txt'

So, how do I transfer a file to my server using PuTTY?

EDIT: Also, calling SCP file.txt myserver:file.txt gives a similar error: file.txt: No such file or directory

2
  • 2
    I dont think putty alone can do the job. WinSCP is a nice GUI tool for secure copy of files, Putty works very well for the job also using the command line tool called pscp.
    – Shadow_boi
    Sep 21, 2011 at 4:28
  • I had the issue of using pscp to copy a file through an intermediate server. This question was the base of me figuring out. The full instructions on taking this question to the next step are here superuser.com/q/577663/57649
    – Scott
    Apr 7, 2013 at 20:45

6 Answers 6

18

Have you tried something like

pscp -l user1 c:\ftp\picture.jpg slacker1:/home/user1/pics

The manual for Putty suggests

To send (a) file(s) to a remote server:

pscp [options] source [source...] [user@]host:target

So to copy the local file c:\documents\foo.txt to the server example.com as user fred to the file /tmp/foo you would type:

pscp c:\documents\foo.txt [email protected]:/tmp/foo


Postscript

The Putty download page lets you download putty.zip - a complete set of Putty tools or you can just download the tools you need (in which case you might have downloaded putty.exe but not yet have downloaded pscp.exe)

5
  • 1
    I have putty installed. I dont seem to have pscp available either within the putty shell or within my local shell. Could you shed a bit more light? Where do you run pscp from? Cheers
    – JonnyRaa
    May 1, 2014 at 13:17
  • 1
    @JonnyLeeds: I run it in a Windows command prompt (cmd) from the Putty installation directory e.g. C:\Program Files (x86)\PuTTY\pscp.exe in my case. You can either put the full path in double quotes (because of the spaces in it) or add the directory to your %PATH% (see other answers here for how to do that). Jan 6, 2015 at 16:04
  • 1
    Hi thanks for the response but all I have in my putty folder is putty.exe, puttygen.exe and a ppk file
    – JonnyRaa
    Jan 21, 2015 at 14:58
  • 1
    @JonnyLeeds: You can either download just pscp.exe from chiark.greenend.org.uk/~sgtatham/putty/download.html or download a putty.zip containing a complete, consistent set of the latest version of Putty tools and replace the sparse set you have. Jan 21, 2015 at 16:45
  • Great answer. One more tidbit: you can often use a period after the remote location's colon if you don't know where you want the file to go. For instance: pscp -l username C:\dir\file.txt server:.
    – TOOGAM
    Jan 28, 2015 at 3:22
11

A solution that doesn't use PuTTY: Connect to server with FileZilla using SFTP to transfer files.

6

There's no way to initiate a file transfer back to/from local Windows from a SSH session opened in PuTTY window.

Though the recent versions of PuTTY support connection-sharing.

While you still need to run a compatible file transfer client (the pscp or the psftp), no new login is required, it automatically (if enabled) makes use of an existing PuTTY session.

To enable the sharing see:
Sharing an SSH connection between PuTTY tools.


Alternative way, is to use WinSCP, a GUI SFTP/SCP client. While you browse the remote site, you can anytime open an SSH terminal to the same site using the Open in PuTTY command.

See Opening Session in PuTTY.

With an additional setup, you can even make PuTTY automatically navigate to the same directory you are browsing with WinSCP.

See Opening PuTTY in the Same Directory.

(I'm the author of WinSCP)

0
0

I couldn't find pscp as suggested above and ended up using WinScp.

It's a client side program with a GUI which picks up your putty configs.

1
0
  1. In PSFTP open the folder you want to put the file in.
    Ex. cd filename
  2. In the command line type: lcd pathtofolder
    Ex. lcd C:\Users\Lyn\Pictures
  3. Click enter and type: put filename
    Ex. put lynhw1.pdf
  4. Click enter and the file should be transferred

Hope it works for you as it does for me.
Note: I did this in PSFTP using Putty.

"PSFTP, the PuTTY SFTP client, is a tool for transferring files securely between computers using an SSH connection" - http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html

Download PSFTP on the http://www.putty.org/ webpage. Under download putty here.

1
-2

If you want to automate this kind of file transfer via .bat:

@echo off

set pw=foobemcfoobar

set inp=input.lst

for /F "tokens=*" %%i in (%inp%) do (

echo %%i

echo y | C:\tmp\pscp.exe -C -agent -pw "%pw%" C:\tmp\files\foo.txt root@%%i:/tmp/

echo "=== Accepting SSH, copying ...==="

 )

(where input.lst is a text file with targets listed)

3
  • While perhaps relevant to the topic, this doesn't answer the question. Mar 20, 2018 at 15:11
  • Also do not suggest people to blindly accept a host key using echo y. You lose security by doing so. Mar 21, 2018 at 13:27
  • mhh agreed, the "echo y" is a security issue. as for relevancy, I just took that file copy thought a step further because I was once in that very situation
    – Nin Kan
    Mar 21, 2018 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .