views:

66

answers:

2

i can get file name via below codes. How can i send this file to remote computer. this remote computer ip: 192.168.2.105 also i can use 51124 port

   class Program
    {
        static void Main(string[] args)
        {

            string[] dosyalarinYollari = System.IO.Directory.GetFiles(@"z:\20071008\1.2.392.200036.9116.2.6.1.48.1215563310.1191800303.305777\", "*.dcm", System.IO.SearchOption.AllDirectories);
            foreach (string s in dosyalarinYollari)
            {
                Console.Write(s+"\n");  // i need to send tihs s file to remote machine
            }

            Console.ReadKey();
        }
    }
A: 

a simple File.Copy passing the location as @"\[ip][drive]$[folder]" is enough to send it to a remote computer if you have rights to log on to that computer.

i'm not really sure about the location string.

GxG
Doesn't this require file and printer sharing to be installed and the drive to be shared properly?
Adrian Grigore
@Adrian Grigore: Yes, it does, but the OP didn't tell what protocol to use. @GxG: You are missing some backslashes in your path, and using an administrative share like `c$` requires administrative permissions on the remote host.
0xA3
if you are logged in as Administrator you can transfer without a problem if you are the Admin on all computers. If you are using network log-on again it isn't that much of a problem, but you could encounter a log-on error. There is no solution for this, just a workaround: before the transfer run a Process.Start with this command: net use \\machinenameorip\driveletter$ /user:domain\username password
GxG
@0xA3 sorry about that \\ip\drive$\folderto copy on the root does not require administrative privileges, just read/write privileges.
GxG
@GxG: No, this is not correct. Accessing an administrative share (i.e. any drive letter + `$` or `admin$`) requires the user to be a member of the local (i.e. on the remote system) Administrators group. Be careful not to confuse these built-in administrative shares with a *hidden* share (i.e. any other share with a name ending in $).
0xA3
okay... sorry about the confusion :)
GxG
+2  A: 

There isn't nearly enough information here to give you a definitive answer, but I can mention some approaches. There are many ways to transfer files between computers, each with pros and cons.

  • Windows file sharing. As mentined by GxG, if this is a Windows (or SMB) environment, and you had the necessary permissions, and file sharing was enabled, you could try \\ipaddress\share\filename.
  • If the remote machine is across the internet, or file sharing is not available, prtocols such as FTP are designed for uploading files to a remote machine, but the remote machine will need to be running an FTP server. .Net has native support for FTP (since .Net 2.0)
  • You could roll your own listener that listens for connections on the target machine, and receives the binary file stream and writes it to disk.
  • If you can connect to the remote machine via SSH, you could look at making a SCP call to upload the file
  • If this is an environment with NFS shares (.e.g the remote machine is possibly a UNIX server) you could mount in NFS and copy.

Some solutions are easier than others. Some require the target machine to be running a server. Some are Windows only, Unix only, etc, etc.

Can you give us more information on your environment, why you need to do this, etc.

Rob Levine
judging by the ip he wants to send it via a intranet connection and judging by the code he is using C# forms therefore is a Windows env.FTP is also available on the intranet but it is far more complicated, and SSH is a good choice if security is an issue.For Win to Unix i would use SSH, but i think my approach would work also(never tried it but in theory everything is done on the Transport Layer of the network therefore the OS wouldn't be an issue)
GxG
@GxG: Actually the IP address seems to belong to a LAN. 192.168.0.0 - 192.168.255.255 is reserved for local area networks.
Adrian Grigore
intranet = inside a networkusually made using a router => the ips 192.168.xxx.xxx which come by default on most routers, or using a switch in which case the ips would be(by default) 10.xxx.xxx.xxx
GxG
@GxG - You are probably right about the intranet, but I can't be sure. If I ever post a question (or answer) containing IP addresses, the first thing I do is anonymise the IP addresses by putting them on 192.168.0.0/24 or somesuch.
Rob Levine
hahaha... that's a sneaky way of doing it... but also is misleading...i would just put it as [someIP] not give an actual IP... or say if it's an intranet IP or an internet IP...
GxG