使用 C# 将文件从一台 PC 传输到另一台 PC?

发布于 2024-08-26 17:46:13 字数 313 浏览 3 评论 0原文

我正在使用 C#。我想将服务器 PC 上的文件传输到我的 PC。两台PC通过网络连接。 我已经在路径中给出了该电脑的 IP 地址,但它没有将文件复制到我的文件夹中。我正在使用以下代码,但它不起作用:

File.Copy(Path.GetFileName(sourceFile), Path.GetDirectoryName(targetpath));

sourceFile 中,我给出了服务器 PC 的 IP 地址 + 文件夹路径,在 targetpath 中,我给出了我的 PC 的文件夹路径我想复制其中的文件。

I'm using C#. I want to get the files that are on the server PC to my PC. Both PCs are connected through network.
I have given IP address of that PC in the path, but it's not copying the files to my folder. I'm using the following code, but it's not working:

File.Copy(Path.GetFileName(sourceFile), Path.GetDirectoryName(targetpath));

In sourceFile I have given IP address + folder path of the server PC and in the targetpath i have given the path of the folder of my PC to which I want to copy the files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝有风,海豚有海 2024-09-02 17:46:13

你为什么使用Path.GetFileName?
该函数仅获取文件名,而不获取完整路径。
File.Copy(string sourceFileName, string destFileName) 的签名意味着您必须使用两个文件的完整路径。

这段代码效果很好:

File.Copy(@"\\server\folder$\test.txt", "test.txt");

Wy do you use Path.GetFileName?
This function get only file name, not full path.
The signature of File.Copy(string sourceFileName, string destFileName) means, that you must use full path to both files.

This code works good:

File.Copy(@"\\server\folder$\test.txt", "test.txt");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文