Transfer files to/from session I'm logged in with PuTTY
Asked Answered
B

13

125

I'm logged into a remote host using PuTTY.

What is the command to transfer files from my local machine to the machine I'm logged into on PuTTY?

Buckwheat answered 30/3, 2011 at 20:32 Comment(0)
L
98

This is probably not a direct answer to what you're asking, but when I need to transfer files over a SSH session I use WinSCP, which is an excellent file transfer program over SCP or SFTP. Of course this assumes you're on Windows.

Lett answered 30/3, 2011 at 20:36 Comment(7)
I tried WinScp but I need to run a command on the box to gain privilages. This does'nt seem possible using WinScp ?Buckwheat
@user470184: correct. I usually run Putty and WinSCP side-by-side. In fact you can start with WinSCP and then there's a context menu to "open this site in Putty" if you so wish.Lett
@GuidoDomenici See my experience with WinSCP here: ux.stackexchange.com/q/35936/4424 :-)Geothermal
blue-sky: To make sudo in WinSCP, see FAQ How do I change user after login (e.g. su root)?Dearborn
WinSCP is not connect to server, because server use credentials by private key. WinSCP is not support SSH-1 key. I am looking for programm how support that type of key. do you have any ideas?Cawnpore
@mishanon WinSCP does in fact support SSH keys (including SSH-1 for over 10 years). When creating a server connection, under the password field, select Advanced >> SSH ---- set protocol version to 1. Then set the key in Advanced >> SSH >> AuthenticationHerriott
Thanks for the help @GuidoDomenici, saved me some time! I know it can be done also from the CMD with pscp and scp, but with WinSCP GUI is much nicer. If anyone have already connected and saved credentials in PuTTy, the WinSCP will automatically ask to import that when you install it. I would suggest anyone to do so, it is quite easy. Of course, it can be imported on a later stage, too.Partook
C
74

  • Click on start menu.
  • Click run
  • In the open box, type cmd then click ok
  • At the command prompt, enter:

    c:>pscp source_file_name userid@server_name:/path/destination_file_name.

For example:

c:>pscp november2012 [email protected]:/mydata/november2012.

  • When promted, enter your password for server.

Enjoy

Cornea answered 1/11, 2012 at 10:18 Comment(8)
And you can invert it like so: 'c:>pscp [email protected]:/mydata/november2012 november2012' to receive files from the remote machine.Overhaul
pscp is part of the putty package but it wasn't on my path so I needed to add it to my path before this worked. pscp should be in the same location as the putty exe. in my case c:\Program Files (x86)\PuTTY.Morose
What if we need to switch users after logging in? sudo su - userOssicle
If you didn't install the entire PuTTY package, you will need to download the pscp program separately from chiark.greenend.org.uk/~sgtatham/putty/latest.htmlFarrel
@SheshraoWankhede is there anyway to combine pscp with the ssh-keygen to bypass the password? thanks in advanceFawne
if you've got "ssh_init: Network error: Cannot assign requested address", maybe you need to add port like here: #62818354Broderick
Can anyone take a look #71095459 post. My problem is same as the above problem. But after follow the process described here I did not get success.Registration
You can also replace the server_name with the server IP if you're getting an error reading: ssh_init: Host does not exist; something like: pscp src_fname [email protected]:dst_fname.Deuteragonist
G
25

PuTTY usually comes with a client called psftp which you can leverage for this purpose. I don't believe you can do it through the standard PuTTY client (although I may be proven wrong on that).

PuTTY only gives you access to manipulate the remote machine. It doesn't provide a direct link between the two file systems any more than sitting down at the remote machine does.

Geothermal answered 30/3, 2011 at 20:40 Comment(3)
psftp is not installed on remote machineBuckwheat
It doesn't need to be. Only on your local machine.Geothermal
And here is some information for transfering files with psftp: pic.dhe.ibm.com/infocenter/tsmscv13/v1r0m0/…Launder
R
13

You can also download psftp.exe from:

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

When you run it you type:

open "server name"

Then:

put "file name"

(Type help to get a full list of commands.)

You can also type get <file name> to download files from a remote machine to the local machine.

Rickie answered 12/7, 2013 at 18:15 Comment(2)
this turns out to be the easiest method from command line, thank!Denise
What directory on the local machine is it running in? I get an error that it cant find the file I want to sent.Hydranth
D
13

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

Though PuTTY supports connection-sharing.

While you still need to run a compatible file transfer client (the pscp or 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 SSH terminal to the same site using Open in PuTTY button.

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)

Dearborn answered 3/3, 2015 at 14:56 Comment(1)
Martin, WinSCP is a blast - good job man. And thank you, really :-)Speck
A
10

Since you asked about to/from, here's a trick that works for the 'from' part. Open the 'Change settings...' screen, Terminal, and under 'Printer to send ANSI printer output to:' select 'Generic / Text Only'

Now on the remote system, run this on one line:

tput mc5; cat whatever.txt; tput mc4

Putty will inform you that the file was saved. What this is doing is putting the terminal into printer mode (tput mc5), printing the file to the screen (cat), and then turning off printer mode (tput mc4). If you don't put all the commands on one line, the screen will appear frozen because Putty is saving all terminal output to a file in the background.

If you're on a more limited system that doesn't have the tput command (e.g. a qnap), you can try printf "\x1b[5i" instead of tput mc5, and printf "\x1b[4i" instead of tput mc4.

The command in the middle is just anything that prints to the screen. So use tail -n 10000 blah.log to download the last 10k lines of the log file, or use a base64 encoder to map a binary file to something you can print (and then decode on your local system):

printf "\x1b[5i"; openssl enc -base64 -in something.zip; printf "\x1b[4i"
Alto answered 7/11, 2018 at 21:19 Comment(2)
You sir, are a genius! I have been search for a way to transfer files over an active SSH session for a while now, and this is the first one that I can easily make work. Do you know if this technique could be modified to work using the terminal on a macOS or Linux based client (i.e. terminals other than PuTTY)?Thain
Darn it, I don't have the Generic / Text Only printer available in my Citrix environment. Hamstrong with access to PuTTY but no SCP client...Vereen
K
8

If it is only one file, you can use following procedure (in putty):

  1. vi filename.extension (opens new file name in active folder on server),
  2. copy + mouse right click while over putty (copy and paste),
  3. edit and save. =>vi editor commands

Edit file permission with next command: chmod u+x filename.extension

Krystynakshatriya answered 19/12, 2013 at 21:57 Comment(2)
This works amazingly well for text files that will fit in the clipboard. For binary files see xxd but you will also need a Windows program to convert binary to hex. e.g. HEXDUMPFarrel
@JamesNewton tnx James, much obligated! My solution came from student days, when we often moved from one computer to another. Installing something was simply not a solution. We had just putty (& scp) on usb disk. But running WinScp just for one file was overkill.Krystynakshatriya
K
4

Look here:

http://web.archive.org/web/20170106202838/https://it.cornell.edu/services/managed_servers/howto/file_transfer/fileputty.cfm#puttytrans

It recommends using pscp.exe from PuTTY, which can be found here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

A direct transfer like FTP is not possible, because all commands during your session are send to the server.

Klansman answered 30/3, 2011 at 20:35 Comment(2)
Thanks, im logging in using a private key which abolve link does not seem to detail ?Buckwheat
@user470184 If you managed to go two years without finding out how, some instructions as to how this may be done can be found at the bottom of: >this page<Bigelow
E
4

If you have to do private key validation; at Command Prompt(cmd), run

First;

set PATH=C:\PuttySetupLocation

Second;

pscp -i C:/MyPrivateKeyFile.ppk C:/MySourceFile.jar [email protected]:/home/ubuntu

Also, if you need extra options look at the following link. https://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html

Euphoria answered 12/4, 2017 at 14:1 Comment(3)
What's the point of set PATH=C:\PuttySetupLocation? Why don't you do C:\PuttySetupLocation\pscp directly? - Even if you want to modify PATH, you should add the new path, not reset it completely.Dearborn
Running set PATH=C:\PuttySetupLocation does not reset the path, only adds PSCP to path as a new entry. Also, you are right about using C:\PuttySetupLocation\pscp .It may be also valid.Leanaleanard
It DOES reset the path.Dearborn
Q
3

Transferring files with Putty (pscp/plink.exe)

The default putty installation provides multiple ways to transfer files. Most likely putty is on your default path, so you can directly call putty from the command prompt. If it doesnt, you may have to change your environmental variables. See instructions here: https://it.cornell.edu/managed-servers/transfer-files-using-putt

Steps

  1. Open command prompt by typing cmd

  2. To transfer folders from your Windows computer to another Windows computer use (notice the -r flag, which indicates that the files will be transferred recursively, no need to zip them up): pscp -r -i C:/Users/username/.ssh/id_rsa.ppk "C:/Program Files (x86)/Terminal PC" [email protected]:/"C:/Program Files (x86)/"

  3. To transfer files from your Windows computer to another Windows computer use: pscp -i C:/Users/username/.ssh/id_rsa.ppk "C:/Program Files (x86)/Terminal PC" [email protected]:/"C:/Program Files (x86)/"

  4. Sometimes, you may only have plink installed. plink can potentially be used to transfer files, but its best restricted to simple text files. It may have unknown behavior with binary files (https://superuser.com/questions/1289455/create-text-file-on-remote-machine-using-plink-putty-with-contents-of-windows-lo): plink -i C:/Users/username/.ssh/id_rsa.ppk user@host <localfile "cat >hostfile"

  5. To transfer files from a linux server to a Windows computer to a Linux computer use pscp -r -i C:/Users/username/.ssh/id_rsa.ppk "C:/Program Files (x86)/Terminal PC" [email protected]:/home/username

For all these to work, you need to have the proper public/private key. To generate that for putty see: https://superuser.com/a/1285789/658319

Quinsy answered 19/3, 2018 at 15:55 Comment(0)
S
2

Since you asked about to/from, here's a trick that works for the 'to' part.

On the local computer:

  • Open the local file in Notepad++ (I'll assume it's a binary file, otherwise this is even simpler!)
  • Ctrl-A to select all.
  • Plugins -> MIME tools -> Base64 Encode with padding.
  • Notepad++ is now displaying a copy of your file encoded only with 'normal' letters and numbers.
  • Ctrl-A, Ctrl-C to copy.

On the SSH session:

  • nano myfile.b64
  • Right-click to paste the encoded text.
  • Ctrl-O, Ctrl-X to save and exit.
  • We now have a base64-encoded copy of your file on the remote machine.

From the command line:

  • base64 -d myfile.b64 > myfile.zip
  • unzip myfile.zip (or whatever you need to do with this file)

File is now transferred. Check the file size, checksum tools, etc. as needed to convince yourself that the file is an accurate copy, then delete the temporary b64.

Spermatid answered 15/3, 2022 at 16:51 Comment(0)
A
0

In that way on windows pscp allows an upload directly (without any request for e.g. key-accepting):

pscp.exe -scp -pw 'my_pw' -v -i my.ppk -l root -batch -sshlog logfile19.txt -hostkey ba:2e:4d:12:68:82:19:a1:d2:22:bc:12:c2:1a:44:a7 hallo4.txt [email protected]:/srv/www/htdocs/xml_parser/hallo4.txt

Aculeus answered 2/12, 2019 at 10:16 Comment(0)
H
0

Same everyday problem.

I just created a simple vc project to solve this problem.

It copies the file as Base64 encoded data directly to the clipboard, and then this can be pasted into the PuTTY console and decoded on the remote side.

This solution is for relatively small files (relative to the connection speed to your remote console).

Installation:

Download clip_b64.exe and place it in the SendTo folder (or a .lnk shortcut to it). To open this folder, in the address bar of the explorer, enter shell:sendto or %appdata%\Microsoft\Windows\SendTo.

You may need to install VC 2017 redist to run it, or use the statically linked clip_b64s.exe execution.

Usage:

On the local machine:

In the File Explorer, right-click the file you are transferring to open the context menu, then go to the "Send To" section and select Clip_B64 from the list.

On the remote console (over putty-ssh link):

Run the shell command base64 -d > file-name-you-want and right-click in the console (or press Shift + Insert) to place the clipboard content in it, and then press Ctrl + D to finish.

voila

Holler answered 10/2, 2021 at 13:49 Comment(2)
The reverse process (from PuTTY to the host) is still complicated. In the context menu of the PuTTY window "Clear Scrollback", clear the screen and print base64 to the full width of the console (stty size helps to find out the size in Linux). Then "Copy All to the Clipboard" and paste it on the host base64 -d from the cygwin kit. clear; base64 -w $(stty size | cut -d\ -f2) < file-to-transfer; readHoller
You can replace your C++ binary with a one-line batch file: @powershell -executionpolicy bypass -command "[Convert]::ToBase64String([IO.File]::ReadAllBytes('%1'))" | clip + If you like the Send To solution, you can use my WinSCP SFTP/SCP client, which adds a "Upload" command to the Send To menu.Dearborn

© 2022 - 2024 — McMap. All rights reserved.