I have to upload files to a ftp site. i am able transfer file to that ftp folder using WINSCP
Now I am trying the same using c# with below code
FtpWebRequest ftpClient = (FtpWebRequest)FtpWebRequest.Create(
"ftp://ftps-xxxxx.xxx.xx.com:xxx/folder/text.txt");
ftpClient.Credentials = new System.Net.NetworkCredential("username", "password");
ftpClient.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
ftpClient.UseBinary = true;
ftpClient.KeepAlive = true;
System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\d\text.txt");
ftpClient.ContentLength = fi.Length;
byte[] buffer = new byte[4097];
int bytes = 0;
int total_bytes = (int)fi.Length;
System.IO.FileStream fs = fi.OpenRead();
ftpClient.KeepAlive = false;
ftpClient.Timeout = -1;
System.IO.Stream rs = ftpClient.GetRequestStream();
while (total_bytes > 0)
{
bytes = fs.Read(buffer, 0, buffer.Length);
rs.Write(buffer, 0, bytes);
total_bytes = total_bytes - bytes;
}
fs.Close();
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
string value = uploadResponse.StatusDescription;
uploadResponse.Close();
when it reach System.IO.Stream rs = ftpClient.GetRequestStream();
below error is occuring
The remote server returned an error: (500) Syntax error, command unrecognized.