How to copy file from linux to windows server using c

16,645

Solution 1

It depends on the type of connectivty between the two machines and on the level of security you have to achieve.

The simplest scenario would be with the two machine on the same LAN and no particular security. In this case possible solution would be:

  • Samba : Share a directory on the Win machine, install/configure Samba on the Linux box. The C program will see the shared disk as a local disk under a specific path (e.g. /win/share).

  • NFS : Alternatively you can export a directory on Linux using NFS and install/configure an NFS product on the Win machine. I see this as a second option, if Samba cannot be used for any reason (e.g. security/authentication).

  • ftp : you will need an ftp server on the Windows machine. It also will be trickier to copy the file via a C program. If I'm not mistaken the ftp client on Linux is interactive and it is not supposed to be used in a script (or via another program) but you should check.

  • http : you will need an http server on the Windows machine and a page that would allow upload (IIS plus some asp page, should suffice) and use libcurl to dialog with it.

More complicated scenario when security is a concerm, would require the use of scp or sftp over and SSL connection. Also the libcurl with https could provide a good enough solution.

My advice is: try Samba first and see if meets your need, all the other options will require more work to you as a programmer.

Solution 2

Mount Windows Share first and then create the file in the mounted directory.

Solution 3

Perhaps you could simply use smbclient? No need to setup any servers or anything, just have a shared drive of some kind on the server.

smbclient //myserver/my_directory <password> -U [domain/]<my_user>

Then you can just 'put' and 'get' whichever files you like betwen the current directory on the linux box and your windows server.

put my_file_to_copy.dat

Thats about it.

Solution 4

Yep - just mount the windows box using whatever network filesystem you want (e.g. Samba) and copy the file into that directory using normal IO primitives.

Mark

Share:
16,645
Admin
Author by

Admin

Updated on November 18, 2022

Comments

  • Admin
    Admin over 1 year

    I have to create a C program which will run on Linux server. It will take information from Oracle database, create a local file and then copy that file to Windows server. I know how to create a local file on Linux server. But what is the way to copy it to windows server from C?