Sftp linux file to windows

How to use SSH to move a file from Ubuntu to Windows?

I am logged onto a windows machine. I am using Putty to login to an Ubuntu machine on the same network. Now I’m trying to move a .c file from the Ubuntu machine, to the Windows machine, edit it there, then move it back to the Ubuntu machine, compile it, and run it. I’m still stuck at obtaining the C file. I’m running this command.

sudo scp odroid:/home/odroid/test/test.c C\Users\MyUser\Downloads 

Instead of moving the file to my Windows machine. somehow I’m creating an un-extended file in the home directory of my Ubuntu machine. What am I doing wrong?

What is an «un-extended file»? Also, which machine is odroid and which machine is the one where you’re running the sudo scp command?

I assume it’s an «un-extended file» by this I mean that I’m creating something called CUsersMyUserDownloads in the home directory. It’s not a directory because I can’t answer it, and it has no extensions, so it’s just an empty file name. Odroid is the Ubuntu machine. I’m logged into it via Putty from the Windows machine. I.E. I’m running Putty and sitting at the Windows machine. I’m logged into the Ubuntu machine. I.E. I’m using the Ubuntu Terminal.

Unless you have installed an SSH server on Windows, you won’t be able to use scp on the remote machine to copy to the local (Windows) machine. Either use pscp.exe from the Windows command line (it is part of the «full» PuTTY install), or (much easier) install and use WinSCP on the Windows machine.

4 Answers 4

In similar cases, I’ve used WinSCP. It’s a Windows SCP client that allows you to browse the Linux file system graphically and scp files back and forth between the 2 machines.

I second WinSCP. I use it often from Windows to access files on Unix/Linux over ssh/sftp. It automates what you are trying to do. It lets you «edit» a file, which behind the scenes, downloads it to a temporary file on your Windows machine, opens it in Notepad (or whatever editor you want), and then when you Save (or Save/Exit), it transfers the file back to the Unix/Linux host.

You’re doing this the very hardest way, but here you go:

  1. Get the wonderful pscp program. I’m not a Windows person at all so all I can tell you is put pscp.exe in your %path% .
  2. On the Windows machine, change directory to C:\Users\MyUser\Downloads
  3. On the Windows machine: pscp test.c odroid:test/ You’ll probably have to type in your Ubuntu password.
  4. On the Ubuntu machine, compile and test.

You have to «pull» the file from your Linux machine, because Microsoft artificially makes computers into «servers» and «clients» (presumably to create false high price points for corporate buyers) and doesn’t see fit to put a SSH server on anything. For that matter, you may need to start sshd on your Ubuntu box.

Honestly, you’d be better off doing text editing on the Ubuntu machine. First, there’s an amazing range of editors of various types available, from NotePad imitators to full-blown IDEs. Second, you’re going to have problems with end-of-line bytes moving the file back-and-forth between Windows and Linux. At some point, the compiler will refuse to compile something, or your Windows editor won’t recognize a single newline character as end-of-line.

Читайте также:  Рейтинг дистрибутивов linux 2023

Well. the Odroid is an off-brand Raspberry Pi. It’s not hooked up to a monitor. I’m developing a C program to run a laser engraver I made that’s attached to the GPIOs on the Odroid. Therefore, I have to use my laptop to write the code, move the code, execute the code, etc.

@Allenph — those details are materially relevant to getting a good answer. I’m not at all certain that whatever distro you’re running on your «odroid» will have an SSH server. It might have dropbear or it might have something else.

The Odroid is running a custom Ubuntu 14.04 image with a built in SSH server which is on by default. Connecting to the Odroid is not a problem. I can view files, execute C programs, etc. The problem is moving the file. The idea is to create a program in Windows with a GUI which will contain a file selector which is used to select a file (Gcode) on the windows machine, rename the file to the file-name accepted by my C program on the Odroid that runs the engraver, and upload it. Then there will be a print button, which tells the Odroid to execute the C program which runs the engraver.

@Allenph — that’s more informative than your question above. WinSCP (winscp.net/eng/index.php) might be your answer. Otherwise, good luck on the Win32 project.

I’ve had to deal with this a lot, and I used to teach a few classes where students needed to work from Windows machines. I’ll describe two methods, and you decide what you like best. Also, warning: I am not a Windows user, I just provide support for them when they need to work with Unix :).

  1. Use WinSCP (http://winscp.net/eng/download.php) WinSCP is just a GUI which works similarly to PuTTY, but you can browse files on the remote server. I’ve found it fairly acceptable, and it’s a GUI so you can just drag and drop files/folders between your local Windows machine, and the remote Ubuntu Linux machine.
  2. Use Sublime Text 3 (https://www.sublimetext.com/3) along with the Sublime SFTP plugin (sorry, you’ll have to search for this) (Ok, I’m basically endorsing this one text editor, but ever since a friend of mine showed it to me, I’ve found it to be my preferred editor in most circumstances. Other editors might let you do something like this; please feel free to check them out. I’m sure everyone has their favorite.) ST is paid software available on a trial basis, and will keep asking you to buy it every few times you save. You can safely ignore this forever and it doesn’t cost you any functionality to use it for free, but just be aware of this (and if you can support the developers. ). The SFTP plugin will also nag you to buy it. This is how I use ST3 and the SFTP plugin (I assume you’ve already installed both).

If you’re going to be working with all files in a remote folder

  • Open ST3 and select File -> «Open Folder»
  • Create a new folder, if you wish. This folder will hold all the files you need to work with. Otherwise, just select a folder.
  • In the left sidebar, right click on the folder name or icon. Choose SFTP/FTP -> «Map to Remote».
  • ST3 will open a config file for setting up your connection. Fill in the important values ( host , user , remote_path ). remote_path should be the directory that your local directory will be «mirroring» in a sense. You can also set upload_on_save to true if you want your files to be copied automatically to the remote server every time you save.
  • Save the file and right-click on the folder name again. This time, pick SFTP/FTP -> «Sync Remote -> Local. «. Warning: if the folder you picked has files in it, this will overwrite them.
  • Select «Yes» when it asks to perform the operations shown in the console.
  • Now your files will show up on the side bar. You can open them, edit them, and save them, all on you local machine. If you did not set the upload_on_save option, you can right click on the file name, or anywhere inside the file and pick SFTP/FTP -> «Sync Local -> Remote. » to copy it back.
Читайте также:  Linux bash переменные окружения

If you’re going to be working with just one file

It may be easier for you to just edit the file in Sublime Text, via the SFTP plugin. This gives you the feeling of working with it locally, but really, only a cached version of it exists on your local machine. The developer of the SFTP plugin calls this the «Server» workflow (you can read about it on their page). Basically:

  • Open ST3, File -> SFTP/FTP -> «Set up server. «
  • Fill in the config file, similarly to how I described above, and save it with a name (maybe the name of the server is a good idea).
  • File -> SFTP/FTP -> «Browse remote. «
  • Use the rather clunky interface to browse for your file, select it, then select «Edit»
  • Edit your file as you wish. Saving uploads it automatically.

I found that ST3 works well enough for my needs. Hopefully this helps you at least somewhat. If you’re not looking for another editor, hopefully WinSCP helps you do what you need to do.

Источник

How To Transfer File From Linux To Windows

transfer file from linux to windows

Copying files in Windows or Linux is simple enough. Copying files between them, though, not so much. The classic copy-paste with a USB stick method does work, but it’s not very efficient.

Instead, you can transfer files using protocols like SMB and SSH and using FTP applications such as FileZilla. We’ve listed step-by-step instructions for these and more methods in the sections below.

Ways to Transfer Files between Linux and Windows

Before you start, do keep in mind that, unlike Windows, Linux is case-sensitive. When entering the commands or file paths, users often forget this and can’t figure out why the file transfer doesn’t work despite following the steps correctly.

With that said, here are the various ways to transfer files between Linux and Windows.

Transfer Files Using SMB

The Server Message Block (SMB) protocol is a client-server communication protocol built into most Linux distributions. Here are the steps to transfer files using SMB:

  1. On your Windows system, locate the folder you’re trying to share.
  2. Right-click the folder and select Give access to > Specific People.
    give-access-to-specific-people
  3. Click on Share and press Done on the next screen.
    choose-people-to-share-with
  4. Next, press Win + R, type cmd , and press Enter.
  5. Type ipconfig and press Enter. Note the IPv4 address of the first adapter on the list.
    ipconfig ipv4 address
  6. On the Linux system, launch the File Browser and click on + Other Locations.
  7. In the Connect to Server field, enter the IP from Step 5 in the following format:
    smb://IP
    ubuntu-network-locations-smb-ip

Transfer Files Using SSH

Secure Shell Protocol (SSH) is a cryptographic network protocol commonly used for remote login. With an SSH client such as PuTTY, you can transfer files between Linux and Windows via the command line. Here are the steps to do so:

ip-addr

  1. On the Windows system, download and install PuTTY if you haven’t already.
  2. On the Linux system, press CTRL + Alt + T to launch the Terminal.
  3. Install and enable SSH with the following commands on Debian-based Linux systems such as Ubuntu:
    sudo apt install ssh
    sudo systemctl enable ssh —now
  4. On RedHat, CentOS, Fedora, and other systems, use these commands instead:
    sudo apt install OpenSSH
    sudo systemctl enable sshd —now
  5. In case you’re getting blocked by the firewall, use the following command:
    sudo ufw allow 22/tcp
  6. Enter ip addr and note the IP Address.

ssh-pscp-file-transfer-syntax

  • On the Windows system, open Command Prompt and use the commands listed below as appropriate.
  • The following command is to copy a single file. The example shows the file named doc.txt being copied from a remote Linux system to the D drive on the Windows system.
    pscp user@host:remote_path/file_name host_path\file_name
  • To copy all files in a folder:
    pscp user@host:remote_path/* host_path\
    eg: pscp anup@192.168.10.65:/home/anup/Desktop/naya/* D:\testfolder\
  • To copy all files & folders in a folder:
    pscp -r user@host:remote_path/ host_path\
    eg: pscp -r anup@192.168.10.65:/home/anup/Desktop/naya D:\testfolder\
  • Transfer Files Using SFTP

    You can also use a third-party tool such as FileZilla to transfer files using SFTP (SSH File Transfer Protocol). Here are the steps to do so:

    1. On the Linux system, follow Steps 1 – 6 from the section above to set up SSH.
    2. On the Windows system, launch FileZilla and select File > Site Manager > New Site.
    3. In the Protocol field, select SFTP – SSH File Transfer Protocol.
      filezilla-sftp-ssh
    4. In the Host field, enter the Linux IP Address from Step 6 of the section above.
    5. Fill in the login credentials of your Linux system and press Connect.
    6. If prompted, enable the Always trust this host option and press OK.
    7. Now that the connection is established, you can transfer files between Windows and Linux by dragging and dropping or right-clicking the file and selecting Upload/Download.
      upload-filezilla

    How to Transfer File from Linux to Windows VM?

    You can easily transfer files from Linux to a Windows VM using a USB Stick. Of course, that’s just one easy method. We have an article that details multiple ways to transfer the files for your further reading.

    Anup Thapa primarily covers Windows systems, networking, and computer hardware at TechNewsToday. Anup has been writing professionally for almost 5 years, and tinkering with PCs for much longer. His love for all things tech started when he got his first PC over 15 years ago. It was a Pentium IV system running Windows XP on a single 256 MB stick. He spent his formative years glued to this PC, troubleshooting any hardware or software problems he encountered by himself. Professionally, Anup has had brief forays into a variety of fields from coding and hardware installation to writing. In doing so, he’s worked with people of different backgrounds and skill levels, from average joes to industry leaders and experts. This has given him not just a versatile skill set, but also a unique perspective for writing that enables him to concisely communicate complex information and solve his reader’s problems efficiently. You can reach out to him at anup@technewstoday.com.

    Источник

    Оцените статью
    Adblock
    detector