Copy a file from the server to a local folder

1

I'm developing a routine for the purpose of copying files from the server to a local folder, but unfortunately it does not copy. The idea is that there are every minute the files are copied.

I left a Sleep(5000) less to facilitate the test. There is no domain on the server and the folder on the server is mapped. Could you take a look?

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;

namespace WindowsService1
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            ThreadStart start = new ThreadStart(CopiarArquivo);

            Thread thread = new Thread(start);

            thread.Start();
        }

        protected override void OnStop()
        {
        }

        public void CopiarArquivo()
        {

            for (int i = 0; i < 600; i++)
            {
                Thread.Sleep(5000);

            File.Copy(@"Z:\PARAM.SAC", @"C:\SACTRM\PARAM.SAC");
            }
        }
    }
}
    
asked by anonymous 06.09.2017 / 03:05

3 answers

0

You can use the UNC nomenclature in the paths.

File.Copy(@"\SVR\PARAM.SAC", @"C:\SACTRM\PARAM.SAC")

Also be aware of read permissions on the source and write file to the destination path.

    
06.09.2017 / 05:15
0

Apparently the problem is permission. Even if you do not have domain on the server, you can create a local user on each computer, but the name and password must be the same on both computers. After running the application with this user, windows interprets that it is the same user. Do not forget to give read permission (File on server) and write (destination folder) to that user.

    
06.09.2017 / 17:22
0

The same routine, except that instead of a Windpws Service I used a Windows Form. It worked. I just need it to be a service. I did not try to solve your Rafael because I would not like to use users. But even with this test with WF you still need to configure users? Thank you.

    
06.09.2017 / 22:24