File.Move & Firewall Port

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to copy and/or move files across servers to the other side of my
firewall. I was wondering if anyone can tell me what port(s) I will need to
open to run these methods in my C# program?

TIA,
Tom
 
Tom said:
Hi,

I need to copy and/or move files across servers to the other side of my
firewall. I was wondering if anyone can tell me what port(s) I will need
to
open to run these methods in my C# program?

The C# program, .NET runtime, copy or move and even files doesn't affect the
problem at all. What service/protocol are you using for the transfer? FTP,
SCP, SFTP, WebDAV, Windows File Sharing, NFS, etc?

Essentially you need the same access to the remote server that you need when
performing the operation by hand from the machine where your code will run.
 
Tom said:
Hi,

I need to copy and/or move files across servers to the other side of my
firewall. I was wondering if anyone can tell me what port(s) I will need to
open to run these methods in my C# program?

TIA,
Tom


It depends on the protocol used (NetBIOS over TCP or SMB direct hosting) and your
authentication requirements (NTLM or Kerberos). NBT uses ports 137, 138 and 139, wile SMB
hosting uses port 445.
NTLM uses port 135.

For a complete list of all possible ports used by Windows Services check this:

http://www.microsoft.com/smallbusiness/support/articles/ref_net_ports_ms_prod.mspx

Willy.
 
Ben,

I am not sure what is happening under the covers so I am not quite sure your
post is helpful.

Here is a simply code snippet that may clarify things a bit:

class MoveIt
{
public static void Main()
{
string LocalPath = @"c:\temp\";
string RemotePath = @"\\MyRemoteServer\MyShare\MyPath\"

try
{
if (File.Exists(LocalPath + "MyTestFile.txt") &&
Directory.Exists(RemotePath))
{
File.Move(LocalPath + "MyTestFile.txt", RemotePath +
"MyTestFile.txt");
}
}

catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}

Does this help?

Thanks,
Tom
 
Tom said:
Ben,

I am not sure what is happening under the covers so I am not quite sure your
post is helpful.

Here is a simply code snippet that may clarify things a bit:

class MoveIt
{
public static void Main()
{
string LocalPath = @"c:\temp\";
string RemotePath = @"\\MyRemoteServer\MyShare\MyPath\"

try
{
if (File.Exists(LocalPath + "MyTestFile.txt") &&
Directory.Exists(RemotePath))
{
File.Move(LocalPath + "MyTestFile.txt", RemotePath +
"MyTestFile.txt");
}
}

catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}

Does this help?

Thanks,
Tom

Your code uses the SMB protocol (all or not using NBT), to copy a file to a remote shared
folder, please see my other post for details about the ports to open.

Willy.
 
Willy,

Thanks for your posts. I have been researching them (DFS and SMB) and it is
very helpful but I have one more question due to our environment that I would
like to run past you.

The destination server is not within my AD tree. I am using a replicated
local user account for the authentication mechanism.

Does this fact change your recommendation?

Thanks again,
Tom
 
Tom said:
Willy,

Thanks for your posts. I have been researching them (DFS and SMB) and it is
very helpful but I have one more question due to our environment that I would
like to run past you.

The destination server is not within my AD tree. I am using a replicated
local user account for the authentication mechanism.

Does this fact change your recommendation?

Thanks again,
Tom


No it doesn't, the fact that you are using a shadow account does not eliminate the NTLM
authentication handshake.
Again, as I said before, try to get rid of NBT and opt for "SMB direct hosting", this way
you don't need to open the NetBIOS related ports 137, 138, 139.

Willy.
 
Willy,

I can see why you are an MVP!! Honestly, this low level networking stuff is
a bit over my head.

I believe what you mean by get rid of NBT is change the resolution scheme in
the method’s destination from Net BIOS, which I believe is the name
resolution mechanism that is resolving the UNC (i.e.
//server/share/path/file), and replace it with something else, preferable SMB
Direct Hosting.

I am not sure what this equates to a couple of abstraction layers up in the
destination of the File.Move method but do I need to change to a URL or a
FQDN?

Are these resolution schemes utilizing SMB Direct Hosting?

Thanks again,
Tom
 
Tom said:
Willy,

I can see why you are an MVP!! Honestly, this low level networking stuff is
a bit over my head.

I believe what you mean by get rid of NBT is change the resolution scheme in
the method’s destination from Net BIOS, which I believe is the name
resolution mechanism that is resolving the UNC (i.e.
//server/share/path/file), and replace it with something else, preferable SMB
Direct Hosting.

I am not sure what this equates to a couple of abstraction layers up in the
destination of the File.Move method but do I need to change to a URL or a
FQDN?

Are these resolution schemes utilizing SMB Direct Hosting?

Thanks again,
Tom


Well, there are two network protocols that can be used to piggy-back the SMB protocol in
Windows:
1. NetBIOS over TCP/IP (NBT), and
2. SMB "direct hosted", that is SMB over TCP/IP.

1 above uses NetBIOS name resolution (and possibly WINS), and is disabled when you disable
NetBIOS over TCP/IP in your network set-up options (per adapter). 2. Is always enabled
(unless you disable File/Printer sharing) on W2K and higher, and uses the DNS name
resolution protocol.
The MPR will automatically select SMB hosting when the UNC path specifies a FQDN DNS name
(or an ip address or an alias name) and not a NetBIOS name. You can force SMB-hosting for
all SMB traffic, simply by disabling NetBIOS over tcp/ip in your network settings.
In your specific case, you simply have to put the IP hostname name or IP address as the
server in the UNC path, if you don't have (or don't want to use) a DNS server available, you
can put the host name in your hosts file (FQDN and alias) and you can disable NetBIOS over
TCP/IP.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top