Java copy files from windows to linux

www.makeuseof.com

Follow MUO

How to Transfer and Share Files Between Windows and Linux

Moving from Windows to Linux and need to copy data across? Use these tricks to transfer or share files from Windows to Linux.

Copying data from a Windows PC to Linux—or in the other direction—can seem intimidating at first. After all, it’s something that seems like it should be simple, but turns out to be difficult.

In truth, sharing files from Windows to Linux is easy, but only if you know how to do it. Ready to find out?

5 Ways to Transfer Files from Windows to Linux

Transferring data between Windows and Linux operating systems is easier than you think. We’ve compiled five ways for you to do this:

  1. Share network folders
  2. Transfer files with FTP
  3. Securely copy files via SSH
  4. Share data using sync software
  5. Use shared folders in your Linux virtual machine

With each of these methods you’ll be able to easily (and in some cases, effortlessly) move files between operating systems.

Let’s look at them in turn and find out which one suits you best.

1. Share Network Folders Between Linux and Windows

The most obvious way to share files between Linux and Windows is to take advantage of network shares. This term refers to folders on one PC that are available to users on other machines. On a Windows-only network this is easy to set up. Adding a Linux device complicates matters slightly, although this can be overcome.

Starting on the Windows machine, right-click the network connection icon in the system tray and select Open Network & internet Settings. Next, click Sharing options and for the current profile enable

  • Turn on network discovery
  • Turn on file and printer sharing

Click Save changes to confirm, then browse to the folder containing the files you wish to share. Right-click the folder, select Properties and open the Sharing tab. Here, click Advanced Sharing then check the Share this folder box.

You can manage access to the folder via Permissions; this refers to local Windows users, not network devices.

Click OK to confirm the change, then open the Security tab in Properties. Configure this to mirror the settings in the Permissions box previously. You shouldn’t need to do too much here as Windows 10 should include a group called Authenticated Users. This is used for remote access to your computer.

Again, click OK when you’re done.

To find the Windows share from your Linux PC, simply open the file browser and select Network. From here, navigate to the Windows-hosted folder, and start exchanging data.

Access a Linux Share From Windows

To move data in the other direction, you’ll need to install Samba on your Linux computer.

Next, set a username for the samba share

You’ll be prompted for a password for the new account (don’t call it «username»!).

Читайте также:  Windows activator loader extreme edition

Next, create a directory to share the data from.

Next, edit the smb.conf file in your text editor:

Add the following to the end of the configuration file:

Make the required changes to suit your own needs, then hit Ctrl + X to exit, tapping Y to save. Next, restart Samba:

You’ll then be able to access the share from Windows. Open File Explorer or your browser and input the IP or hostname of the remote Linux device, followed by the folder name. In our example, this is

2. Copy Files via SSH From Windows to Linux

With SSH enabled on your Linux device, you can send data via the command line from one computer to another. For this to work, however, you will need to set up an SSH server on your Linux machine.

Start by opening a terminal and updating and upgrading the OS.

Once complete, install the SSH server. The OpenSSH server is a good option.

Wait while it installs. To check at any time if the OpenSSH server is running, use

To transfer data from Windows, use an SSH client like PuTTY. This needs the PSCP tool downloading to your Windows system to run alongside PuTTY. Find both on the PuTTY homepage.

Note that while PuTTY will need installing, PSCP won’t. However, it should be saved in the root of the C:\ drive or else set up as an environment variable. You’ll also need to confirm the IP address of the Linux device. Check this on the box with

With a connection established, you can send data like this:

You’ll be prompted for your password for the Linux computer before the transfer commences.

Want to copy data from Linux to Windows in the same SSH session? This command will download the specified file to the current directory:

Note the lone period at the end—include this or the transfer will not work.

3. How to Transfer Files From Linux to Windows Using FTP

A file transfer protocol (FTP) application with SSH support can also be used. Transferring files via SFTP in a mouse driven user interface is arguably easier than relying on typed commands.

Again, an SSH server must be running on the Linux machine before you start. You should also ensure you have installed an FTP app like FileZilla, which has SFTP support.

To use this method, run FileZilla, then open File > Site Manager. Create a New Site, taking care to set the Protocol to SFTP. Add the target IP address in Host, then the username and password, setting the Logon Type to Normal.

Click Connect when ready, then use the FTP interface to drag and drop files between the two computers.

4. Share Files Between Linux and Windows With Resilio Sync

Another option you should consider is a file syncing program. These are typically cross-platform and use an encrypted key to manage the connection between devices.

All you need to do is install the app, nominate a sync folder, then create the key. Set this up on the second PC and your data will then sync. Two good options are available for this:

  1. Resilio Sync: formerly known as BitTorrent Sync, Resilio is available on almost any platform you can think of. There is a paid version, but the free option is enough for syncing two devices.
  2. SyncThing: for Linux, Windows, macOS, and Android, this Resilio Sync alternative offers a similar feature without the paid component.

Our guide to using Resilio Sync (as well as Syncthing) will guide you through setting up network file transfers between computers.

5. Create and Mount a VirtualBox Shared Folder in Linux

Many people don’t run a separate Linux machine. Instead, it’s common to run Linux in a virtual machine (VM). But is there are way to transfer files between Windows and Linux when one is installed in a VM?

Fortunately, yes. With VirtualBox you can create a virtual shared directory for data syncing.

If you’re running Windows in a VM on Linux (or vice versa), VirtualBox is already set up for sharing. Ensure you have the Guest Additions installed on your virtual machine before proceeding.

Читайте также:  Windows 10 как сделать скриншот активного окна

In the VirtualBox manager, select the VM and choose Start > Headless Start (Alternatively start the VM then open Devices > Shared Folders). When the status displays that the machine is running, open right-click the VM and select Settings > Shared Folders.

Here, select Machine Folders then click the + symbol on the right (or right-click and select Add Shared Folder). Browse the Folder Path, find the directory you want to use, set a name (if necessary) then OK.

Use the Auto-mount checkbox if you want the share to be available whenever the VM runs. Click OK again to confirm and exit. When you reboot the VM, the share will be ready to swap data between the host PC and guest operating system

Sharing Files Between Windows and Linux Is Easy

Whether you’re new to Linux, or you find Windows unfamiliar, sharing data between them is easier than you think.

We’ve looked at several methods. We’d recommend you try all of them and work out which one you’re most comfortable with.

If you’re syncing data to Linux, there’s a good chance you’re migrating your computing from Windows. Check our guide to switching from Windows to Linux for more tips.

Why are there so many different USB cable types? Learn the differences between USB connector types and how to buy the best USB cables.

Deputy Editor for Security, Linux, DIY, Programming, and Tech Explained. He also produces The Really Useful Podcast and has extensive experience in desktop and software support. A contributor to Linux Format magazine, Christian is a Raspberry Pi tinkerer, Lego lover and retro gaming fan.

Subscribe To Our Newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

One More Step…!

Please confirm your email address in the email we just sent you.

Java code to copy files from one linux machine to another linux machine

I wants to write a program to copy/create one file from linux machine to another linux/windows machine in java. I tried below code,which will create one file in another windows machine..

It worked in WIndows to windows. But when I tried from linux machine .it is creating folder in the linux machine itself. Could any one help me to solve this?

4 Answers 4

You should use something like FTP to move files between unix machines.

JSCH is a good API for that.

You will need some user authentication tho.

Here is an example:

To work the above application ,We have to add one more line in the above code, session.put(«StrictHostKeyChecking», «no»); just before session.connect(); Complete program is

You can’t create a file on another machine this way under Linux. You are using Windows share folders, which is not the way files are shared in Linux world. You have two choices :

  1. either by connecting the two filesystems, with NFS for example (a kind of Unix file sharing), in such a way that the second filesystem is mounted on the first one so that a path will lead you to the second machine in a way similar to Windows file sharing paths.
  2. either by using some protocol to transfer your file (FTP, RSYNC, etc).

You can use this code snippet to copy files to another linux machine.

For more details reach out THIS similar post

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

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

How to copy file from one location to another location?

I want to copy a file from one location to another location in Java. What is the best way to do this?

Читайте также:  Windows automated systems recovery

Here is what I have so far:

This does not copy the file, what is the best way to do this?

6 Answers 6

You can use this (or any variant):

Also, I’d recommend using File.separator or / instead of \\ to make it compliant across multiple OS, question/answer on this available here.

Since you’re not sure how to temporarily store files, take a look at ArrayList :

To move a List of files into a single directory:

Using Stream

Using Channel

Using Apache Commons IO lib:

Using Java SE 7 Files class:

Or try Googles Guava :

Compare time:

Use the New Java File classes in Java >=7.

Create the below method and import the necessary libs.

Use the created method as below within main:

NB:- fileFrom is the file that you want to copy to a new file fileTo in a different folder.

Overwriting Existing Files: Files.move()

Copy a file from one location to another location means,need to copy the whole content to another location. Files.copy(Path source, Path target, CopyOption. options) throws IOException this method expects source location which is original file location and target location which is a new folder location with destination same type file(as original). Either Target location needs to exist in our system otherwise we need to create a folder location and then in that folder location we need to create a file with the same name as original filename.Then using copy function we can easily copy a file from one location to other.

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

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

How to transfer files from Windows to Ubuntu on Virtualbox?

How should I transfer files from Windows to Ubuntu installed on Virtualbox? When I plugged in a USB, it only pops up in Windows.

How can I see it in Ubuntu?

6 Answers 6

There are 2 ways, which I normally use

Option 1: Before booting up Ubuntu, inside Virtualbox Ubuntu VM settings, specify a share folder. Then after logged in to Ubuntu, create a new directory for example /media/vboxshared and mount that drive using the command sudo mount -t vboxsf SHARENAME /media/vboxshared . Enter your password when it prompts for the password.

Option 2: Before booting up Ubuntu, add a new Network adapter and select ‘Bridged Adapter’. Then after logged in to Ubuntu, run the command ifconfig -a | more to get the ip address of that new network adapter. In Windows, use WinSCP or FileZilla to transfer the file to Ubuntu

Thank you for Alvin Sim’s answer. Though it is clear, I still spend some time to do everything correct. OK, here are my detailed steps using Alvin Sim’s Option 1.

  1. Before starting your Guest
  2. Go to VirtualBox Manager
  3. Select your interested Guest
  4. Go to Guest Settings
  5. In Guest Settings, scroll the left side-menu, and go to Shared Folders
  6. In Shared Folders, add your interested folder in the Host machine
  7. After adding your Host folder path, you will see an updated Folders List in Shared Folders. Remember your newly folder Name shown in this list. Say it is HOST_SHARE .
  8. Click OK and save your changes.
  9. Start your Guest machine
  10. In Guest machine, create a new folder, e.g. GUEST_SHARE

In Guest terminal, type

If you see the error mount: wrong fs type, bad option, bad superblock on … , this means you first need to install virtualbox-guest-utils .

Then run the mount command again

You shall find your stuffs in this GUEST_SHARE folder.

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