casit
asked on
FTPwebresponse protocol violation error.
I have the following function which worked fine. Basically its an ftp upload function for a C# GUI to upload mp3s to a server. However it throws a weird error now when I try to connect to ftp.
"The underlying connection was closed: The server committed a protocol violation."
Here is the code. Anybody have any idea on what is wrong?
FTP login info is
host=mydgbc.org
username=test@desertgatewa ybaptist.o rg
password=testtest
and here is my c# code
[code]
private void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebReque st.Create( new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserI D, ftpPassword);
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Specify the data transfer type.
reqFTP.UseBinary = true;
// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;
// The buffer size is set to 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
FileStream fs = fileInf.OpenRead();
try
{
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
// Close the file stream and the Request Stream
strm.Close();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
//MessageBox.Show(response .BannerMes sage);
MessageBox.Show(response.S tatusDescr iption);
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message , "Upload Error");
}
}
[/code]
"The underlying connection was closed: The server committed a protocol violation."
Here is the code. Anybody have any idea on what is wrong?
FTP login info is
host=mydgbc.org
username=test@desertgatewa
password=testtest
and here is my c# code
[code]
private void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebReque
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserI
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Specify the data transfer type.
reqFTP.UseBinary = true;
// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;
// The buffer size is set to 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
FileStream fs = fileInf.OpenRead();
try
{
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
// Close the file stream and the Request Stream
strm.Close();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
//MessageBox.Show(response
MessageBox.Show(response.S
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message
}
}
[/code]
Hi
Without any problem it worked for me, i dint change ur code except the file name
Without any problem it worked for me, i dint change ur code except the file name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And sorry, for testing i have uploaded my files to ur site named "winzip.log", u can check that using the following link:
ftp://test@desertgatewaybaptist.org@mydgbc.org/
ftp://test@desertgatewaybaptist.org@mydgbc.org/
ASKER
Yeah I was an idiot. I realized that the folder had been renamed. After I renamed it back to the old name it works fine. I will split the points since it was my fault and I solved the problem.
ASKER