Using ftp in C# to send a file
Posted
by pm_2
on Stack Overflow
See other posts from Stack Overflow
or by pm_2
Published on 2010-05-05T11:28:22Z
Indexed on
2010/05/05
11:38 UTC
Read the original article
Hit count: 135
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:
The requested URI is invalid for this FTP command.
Please can anyone tell me why? Am I using this incorrectly?
© Stack Overflow or respective owner