Exemplo n.º 1
0
        private void CopyProc(object obj)
        {
            Console.WriteLine("CopyProc");
            SNetworkFileCopier copier = (SNetworkFileCopier)obj;

            try
            {
                Console.WriteLine("Connecting to remote");
                AppendToLog("Connecting to remote: " + copier.NetworkFolderPath);
                copier.ConnectToRemote();
                Console.WriteLine("Connected");
                AppendToLog("Connected to remote");
                string sfn = Path.GetFileName(copier.LocalFilePath);
                Console.WriteLine("Copying: " + sfn);
                string destination = copier.NetworkFolderPath + "\\" + sfn;
                AppendToLog("Copying " + copier.LocalFilePath + " to " + destination);
                File.Copy(copier.LocalFilePath, destination);
                Console.WriteLine("Copied");
                AppendToLog("Copied");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in CopyProc: " + ex.Message);
                AppendToLog(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnCopy_Click(object sender, EventArgs e)
        {
            string str = txtLocalFile.Text;

            try
            {
                if (!File.Exists(str))
                {
                    MessageBox.Show("Local file not exists");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            SNetworkFileCopier fileCopier = new SNetworkFileCopier();

            fileCopier.LocalFilePath     = str;
            fileCopier.NetworkFolderPath = txtNetworkFolderPath.Text;
            fileCopier.Username          = txtUsername.Text;
            fileCopier.Password          = txtPassword.Text;

            Thread thr = new Thread(new ParameterizedThreadStart(CopyProc));

            thr.IsBackground = true;
            thr.Start(fileCopier);
        }