Pandora
Pandora

Reputation: 233

Copy file from linux to windows share with C# (.NET core)

I'm using .NET core for an application running on a Linux machine (a docker container, to be exact)

How can I copy a binary file from there to a windows network share (including username & password)?

All solutions I've found were windows specific, but nothing related to Linux.

Upvotes: 10

Views: 6381

Answers (2)

praveenSri
praveenSri

Reputation: 11

apt-get update && apt-get install smbclient -y

smbclient //IPADDRESS/shared -c 'put myfile.txt' -U mydomain/username%password -m SMB2

Using P/Invoke

Upvotes: 0

Nick Edwards
Nick Edwards

Reputation: 610

How about by using CIFS from Samba to mount the share. Once you've installed cifs-utils, you could try something like:

 mkdir ~/localMountPoint
 mount -t cifs //server/share ~/localMountPoint -o user=myname,pass=mypassword

There's a more in depth tutorial here: https://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/

Upvotes: 4

Related Questions