本文介绍了在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发送文件
发布评论