在C#中使用FTP发送文件

编程入门 行业动态 更新时间:2024-10-24 22:26:12
本文介绍了在C#中使用FTP发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图发送使用ftp文件。我有以下的code:

I'm trying to send a file using ftp. I have the following code:

string server = "x.x.x.x"; // Just the IP Address FileStream stream = File.OpenRead(filename); byte[] buffer = new byte[stream.Length]; WebRequest request = WebRequest.Create("ftp://" + server); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); Stream reqStream = request.GetRequestStream(); // This line fails reqStream.Write(buffer, 0, buffer.Length); reqStream.Close();

但是,当我运行它,我得到以下错误:

But when I run it, I get the following error:

请求的URI是该FTP命令无效。

The requested URI is invalid for this FTP command.

请谁能告诉我为什么吗?我使用这个错误?

Please can anyone tell me why? Am I using this incorrectly?

推荐答案

我想你需要指定的路径和文件名,你要上传过,所以我想应该是的:

I think you need to specify the path and filename you're uploading too, so I think it should be either of:

WebRequest request = WebRequest.Create("ftp://" + server + "/"); WebRequest request = WebRequest.Create("ftp://" + server + "/filename.ext");

更多推荐

在C#中使用FTP发送文件

本文发布于:2023-11-07 22:37:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   FTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!