
Whe I try to upload a file to an FTP Server I always get an error on "ftpWebRequest.GetRequestStream();"
The Error is:
System.Net.ProtocolViolationException: Can not send content-body with this verb-type
at System.Net.FtpWebRequest.GetRequestStream()
I cannot find the problem in my code which is the following:
public void ftpUploadFile(Filename _file)
{
System.IO.Stream ioStream;
System.IO.StreamReader ioStreamReader, responseReader;
System.String strReadLine;
System.Text.Encoding utf8;
System.Byte[] bytes;
FileIOPermission permission;
FilePath filePathDest;
int length;
;
if (_file != '')
{
try
{
permission = new FileIOPermission(_file,"RW");
permission.assert();
// BP Deviation Documented
ioStreamReader = new System.IO.StreamReader(_file);
utf8 = System.Text.Encoding::get_UTF8();
if (ioStreamReader)
{
bytes = utf8.GetBytes( ioStreamReader.ReadToEnd() );
ioStreamReader.Close();
// Marshaling .NET to X++
ftpObject = System.Net.WebRequest::Create(ftpHostName + @"/" + _file);
ftpWebRequest = ftpObject;
if (ftpWebRequest)
{
ftpWebRequest.set_KeepAlive(false);
ftpWebRequest.set_UsePassive(true);
ftpWebRequest.set_Method(#UploadFile);
ftpWebRequest.set_UseBinary(true);
ftpWebRequest.set_Timeout(ftpTimeOut);
ftpWebRequest.set_ReadWriteTimeout(ftpTimeOut);
ftpWebRequest.set_ContentLength(bytes.get_Length());
this.setFTPCredentials();
ioStream = ftpWebRequest.GetRequestStream();
ioStream.Write(bytes, 0, bytes.get_Length());
ioStream.Close();
webResponse = ftpWebRequest.GetResponse();
responseReader = new System.IO.StreamReader(webResponse.GetResponseStream());
info(responseReader.ReadToEnd());
webResponse.Close();
}
CodeAccessPermission::revertAssert();
}
}
catch(Exception::CLRError)
{
exception = CLRInterop::getLastException();
if(exception != null)
{
exception = exception.get_InnerException();
checkFailed(exception.ToString());
}
}
}
}
Any Ideas?
*This post is locked for comments
I have the same question (0)Sending files over a web request should use the POST method.
Try
ftpWebRequest.set_method("POST");