I'm running the following:
try
{
var ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://webftp.ftp.com");
ftpWebRequest.Credentials = new NetworkCredential("user", "password");
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
using (var inputStream = File.OpenRead(@data))
using (var outputStream = ftpWebRequest.GetRequestStream())
{
var buffer = new byte[1024 * 1024];
int totalReadBytesCount = 0;
int readBytesCount;
while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0)
{
outputStream.Write(buffer, 0, readBytesCount);
totalReadBytesCount += readBytesCount;
var progress = totalReadBytesCount * 100.0 / inputStream.Length;
uploader.ReportProgress((int)progress);
}
}
}
catch (Exception es)
{
MessageBox.Show(es.ToString());
}
@data is the full local path to the file.
The error i receive everytime is as follows:
System.Net.WebException: The requested URI is invalid for this FTP command. at System.Net.FtpWebRequest.GetRequestStream()
I've tried the ftp connection via cmd and it works perfectly fine.