将文件从一个路径复制到另一路径 [英] copy file from one path to another

查看:94
本文介绍了将文件从一个路径复制到另一路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要将系统中的一个文件传输到server中的指定路径.下面是我做的代码.但是它抛出错误,提示不正确的功能.

Hi all,

i need to transfer one file fom my system to a specified path in server.below is the code i did.but its throwing me error saying incorrect function.

string username = "rsdfsf";
            string password = "sfsfsdf03";
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            WindowsIdentity identity = new WindowsIdentity(username,password);   //Here its throwing the error....     
    WindowsIdentity.GetCurrent();
            WindowsImpersonationContext context = identity.Impersonate();

            try
            {
                File.Copy(@"C:\Documents and Settings\aj99823\Desktop\project\employeedetails1.txt", @"\\\\149.223.26.33\\D:\\Developers\muralim\TRW.HRM.Headcount_LMSFeed\Log\empps.txt", true);
            }
            catch
            {
                context.Undo();
            }  


任何人都可以请我帮忙......... ???


can anyone plsssss help me.........???

推荐答案

我并不惊讶它不起作用-我会如果确实如此,那一定会感到惊讶(甚至感到难过).

想一想您要做什么:

通过互联网从本地PC读取文件文件,并将其写入世界上其他地方的计算机的指定文件夹,指定硬盘驱动器中."

如果您可以轻松地做到这一点,那么什么会阻止我这样做呢?并使用远程服务器进行Internet备份或文件共享设备?如果它填满了一点,请删除您的文件以为我留出空间?

如果要这样做,则需要查看在软件和服务器之间建立FTP连接(假设已将其配置为接受FTP请求)并以这种方式传输文件. Google可以在这里为您提供帮助-它找到了以下内容: C#FTP客户端库 [ ^ ]
I''m not surprised it doesn''t work - I would be amazed (and rather saddened) if it did.

Think for a moment about what you are trying to do:

"Read file file from your local pc, and write it to a specified folder, of a specified hard drive, of a computer somewhere else in the world, via the internet."

If you could do it that easily, what would stop me doing the same? And using your remote server for an internet backup, or file sharing device? And if it filled up a bit, deleting your files to make room for mine?

If you want to do that, then you need to look at setting up an FTP connection between your software and the server (assuming it is configured to accept FTP requests) and transfer the file that way. Google can help you there - it found this: C# FTP Client Library[^]


这篇关于将文件从一个路径复制到另一路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆