3

I have two computers connected to the same router (so they are essentially connected in a LAN). Both run some GNU+Linux distribution. I have a bunch of files, in a directory ~/A/ on my first computer that I would like to transfer to my second computer.

The names of the files in A are contained in a certain list, say names_list. Now I would like for each of these files to be accessible via a local address, provided with reference to the router (such as 192.168.2.1:2112/name_of_file or something similar), so that the second computer may simply download each file one-by-one when given the names_list.

How can I do this? The downloading part is trivial, I am asking mainly regarding setting up the host computer to provide files at specific local addresses.

  • 1
    If you want all files in A, scp -pr ${IPADDR}:A . To download one-by-one, something like for file in $(<names_list) ; do scp ${IPADDR}:A/${file} . ; done – user4556274 Feb 12 '17 at 17:54
  • The problem isn't with the download part. How do I make the host computer set up this file directory and host all the files in the manner described? – Aalok Feb 12 '17 at 17:56
  • not sure what you mean by "set up". All this requires is [Open]SSH on both ends, which most linux distributions include by default. If you're missing the server parts of the OpenSSH package, install them per your distribution's package manager, e.g., apt install openssh-server. – user4556274 Feb 12 '17 at 17:59
  • By set up I mean simply to make a certain file path/to/file available on a local address. – Aalok Feb 12 '17 at 18:02
  • Having the files served through NFS would be a good option too. – Kusalananda Feb 12 '17 at 18:11
2

Plenty of remote filesystems exist. There are three that are most likely to be useful to you.

  • SSHFS accesses files via an SSH shell connection (or more precisely, via SFTP). You don't need to set up anything exotic: just install the OpenSSH server on one machine, install the client on the other machine, and set up a way to log in from the client to the server (either with a password or with a key). Then mount the remote directory on the first computer:

    mkdir ~/second-computer-A
    sshfs 192.168.2.1:A ~/second-computer-A
    

    SSHFS is the easiest one to set up as long as you have access to all the files through your user account on the second computer.

  • NFS is Unix's traditional network filesystem protocol. You need to install an NFS server on the server. Linux provides two, one built into the kernel (but you still need userland software to manage the underlying RPC protocol and the additional lock protocol) and one as a pure userland software. Pick either; the kernel one is slightly faster and slightly easier to set up. On the server, you need to export the directory you want to access remotely, by adding an entry to /etc/exports:

    /home/zakoda/A 192.168.2.2(rw,sync)
    

    On the second computer, as root:

    mkdir /media/second-computer-A
    mount -t nfs 192.168.2.1:/home/zakoda/A /media/second-computer-A
    

    By default NFS uses numerical user and group IDs, not user and group names. So this only works well if you have the same user IDs on the server and on the client. If you don't, set up nfsidmap on the server.

  • Samba is Windows's network filesystem protocol (rather, it's an open-source implementation of the protocol, which was called SMB and is now called CIFS). It's also available on Linux and other Unix-like systems. It's mainly useful to mount files from a Windows machine on a Unix machine or vice versa, but it can also be used between Unix machines. It has the advantage that matching accounts is easier to set up than with NFS. The initial setup is a bit harder but there are plenty of tutorials, e.g. server and client.

0

There are more ways to achieve this. Making http.server will give you lots of control, but you need some basic python knowledge.

Alternatively, this might help setting up A directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.