Copying files to file-server

M

Mantorok

Hi all

C# v2.0

I want to update a server which is in our DMZ, to access this server I
always need to enter the admin user id and password.

I want to copy some files overnight to this server using a C# app, is this
possible? Can I provide the credentials to enable me to access the server?

Thanks
Kev
 
S

Shine Xavier

One good option would be to wrap the file copy operation into an exe (which
is very much possible) and use the "Schedule Task Wizard" to run this as a
daily task using the required user credentials.

Hope this helps!
Thanks -
 
M

Mantorok

Thanks, but the server is on a different network, and the admin account is
local to that server.

Presumably that rules out a scheduled task running under the account? Or am
I wrong?

Kev
 
S

Shine Xavier

How do you access the server in the DMZ currently and transfer the files?
The reason why i am asking this is to understand the ports that are opened
in the firewall currently.

Thanks -
 
M

Mantorok

The network guys setup an ip-route on my PC so I can access the server using
a local ip address.

Then I have to provide a usename/password.

Kev
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Mantorok said:
Hi all

C# v2.0

I want to update a server which is in our DMZ, to access this server I
always need to enter the admin user id and password.

Enter it where?
I want to copy some files overnight to this server using a C# app, is this
possible? Can I provide the credentials to enable me to access the server?


You will ahve to execute the process as the admin user.

can you use FTP? it would be a better solution IMO
 
I

Ignacio Machin \( .NET/ C# MVP \)

Mantorok said:
The network guys setup an ip-route on my PC so I can access the server
using a local ip address.

Then I have to provide a usename/password.

so basically you use a "regular" windows copy procedure, in this case you
have to impersonate teh admin.
 
M

Mantorok

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,



Enter it where?

Windows prompts me when I access the share (\\172.16.19.12\f$).
You will ahve to execute the process as the admin user.

can you use FTP? it would be a better solution IMO

Yes, that would be good, the only problem is I don't think FTP is running on
the server.

Kev
 
W

Walter Wang [MSFT]

Hi Kev,

You can use NetUseAdd to use a specific account to connect to the network
share. Please see following thread for a complete discussion (it also has
sample code in C#, though the ACL part isn't relevant here, but I think
it's also useful for reference):

# How to grant Access on Files on a share drive? -
microsoft.public.platformsdk.security | Google Groups
http://groups.google.com/group/microsoft.public.platformsdk.security/browse_
thread/thread/156045ffc5f40605


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Shine Xavier

Hi,

I just tried this and should ideally work for you as well.

Step1:
Create a local user with the SAME credentials (login/password) that you use
you login to your server in DMZ.
AND make this user part of local Administrator group.

Step2:
Create the ConsoleApplication1.exe using the code below:

using System;
using System.IO;
using System.Diagnostics;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string path = @"c:\temp\MyTest.txt";
string path2 = @"\\[Put Destination IP here]\c$\TEMP\MyTest.txt";//<-[Put
Destination IP here]

try
{
// Create the file and clean up handles.
using (FileStream fs = File.Create(path)) {}

// Ensure that the target does not exist.
File.Delete(path2);

// Copy the file.
File.Copy(path, path2);
Console.WriteLine("{0} copied to {1}", path, path2);

// Try copy the file, which should succeed.
File.Copy(path, path2, true);
EventLog.WriteEntry("FileCopyOverDMZ-Scheduled Task","Successfully
Copied!!!", EventLogEntryType.Warning);
}

catch (Exception e)
{
EventLog.WriteEntry("FileCopyOverDMZ-Scheduled Task",e.Message,
EventLogEntryType.Error);
}
}
}
}

Step3:
Now create a scheduled task and provide the credentials for the local user
that was created in Step1.
This enables the application to copy the files as it would impersonate the
administrator role of the server in DMZ.

Could you please give a try and let me know the outcome(from the Event
Logs)?

Hope this helps!
Thanks-
 

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

Top