views:

4983

answers:

7

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?

+7  A: 

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

Tomasz Tybulewicz
A: 

Or use FTP. There's plenty of FTP libraries you can link into your Linux C code.

Andrew
A: 

The windows machine should provide a mean to accept this behaviour first (FTP comes to mind). You may develop an application to run on windows machine to accept the file, but easier is use one of the already developed ones.

filezilla is an example.

For the actual question, how to upload the file, any ftp client would do the trick.

tafa
+6  A: 

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.

Remo.D
+1  A: 

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.

Scott Bennett-McLeish
A: 

How about using SMTP and mailing it?

Ray
+1  A: 

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

MarkR