55

I am trying to set up a connection and transfer files using putty on a windows 10 platform. I have verified that the default port in putty is 22. When I run the command in the command line to connect and transfer files though I get the above error. Any idea why this is or what I should do?

3 Answers3

126

Did you try:

pscp -P 22 c:\documents\foo.txt user@example.com:/tmp/foo
Ron Klein
  • 8,650
  • 9
  • 50
  • 83
Martha
  • 1,276
  • 1
  • 3
  • 3
  • Thank you very much. –  Sep 06 '20 at 21:07
  • 9
    why does the port have to be explicitly defined? – mlhDev Nov 03 '20 at 14:50
  • 1
    @mlhDev, when running `pscp` with `-v` (verbose), it prints `Connecting to example.com port 0`. So, it seems like default port for pscp is 0, not 22, which is weird. – Alex Che Nov 11 '20 at 14:34
  • 6
    This is a [known bug](https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/pscp-port-0.html) on clean machines and it has two workarounds. The answer by TomRod gives the preferable one-time permanent solution. – yoyoma2 Nov 12 '20 at 19:26
  • Worked for me. Although I was hoping it would 22 as it's default port. – Arjun Mudhaliyar Nov 19 '20 at 13:11
  • I used -p (small) which is for preserved file attributes.It should be -P (capital) which is for port. to check all options, type pscp in command prompt. – ImFarhad Dec 17 '20 at 17:39
15

I had to go into the Putty Default Settings and "Save" them again, despite port 22 showing as the default. Worked for me to avoid adding the -P 22 option every time.

TomRod
  • 161
  • 1
  • 5
  • 1
    This was it for me too. Not sure what it takes to get into that state, but for me it was on a pretty new install. The "Default Settings" saved session in putty showed port 22, and reloading kept port 22. But sure enough, saving it again made pscp start using port 22 for every IP I gave it, instead of the port 0 it had been using for every IP. Bizarre – aggieNick02 Nov 12 '20 at 04:39
  • 1
    This should be the accepted solution as it is a one-time fix. The answer should specify **Putty** Default Settings since they also affect the distinct pscp.exe tool. – yoyoma2 Nov 12 '20 at 19:32
  • For me, both `-P 22` and **saving** the Putty's Default Settings again worked but I would prefer Default Settings. Thanks @Martha – Jawad Khan Nov 25 '20 at 08:24
5

I had the same error and ended up at this page. The -P 22 did not solve my problem.

I use Putty saved sessions and double checked my command line and had the same error as the OP.

I was using:

pscp -l SESSION_NAME_IN_PUTTY ip:/remote_path local_path

I reviewed the command line options for pscp and changed the -l to -load and it worked.

The final command looked like:

pscp -load SESSION_NAME_IN_PUTTY ip:/remote_path local_path

Note: If you still have the error, please review your spelling of SESSION_NAME_IN_PUTTY and ensure it is an exact match. One letter off, can cause the same error.

Taterhead
  • 4,845
  • 2
  • 23
  • 35