private void btnftptest_Click(object sender, EventArgs e, bool test)
{
string filename;
if (test == true)
{
filename = "delete_me";
toolStripStatusLabel1.Text = "Attempting to upload test file to server, standby.....";
try
{
File.WriteAllText("delete_me", "This is a test file by the ACI Multi Banlist Compiler program. Delete this file");
}
catch (Exception ex)
{
MessageBox.Show("There was an error generating test file for upload: " + ex.Message);
return;
}
}
else
{
toolStripStatusLabel1.Text = "Attempting to upload banlist to server, standby.....";
}
string ftpServerIP = txthost.Text;
string ftpUserID = txtusername.Text;
string ftpPassword = txtpw.Text;
string ftpHome = txtpath.Text;
string ftpPort = txtport.Text;
ftpHome = ftpHome.Trim(@"/\".ToCharArray()).Replace(@"\", "/");
filename = "delete_me";
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + ftpServerIP + "/" + ftpHome + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + ":" + ftpPort + "/" + ftpHome + "/" + fileInf.Name));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserID, 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;
reqFTP.Timeout = 15000;
// 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();
fs.Close();
}
catch (Exception ex)
{
if (test == true)
{
MessageBox.Show("Error uploading test file to server: " + ex.Message);
toolStripStatusLabel1.Text = "Error uploading test file to server!";
return;
}
toolStripStatusLabel1.Text = "Error uploading banlist to server!";
MessageBox.Show(ex.Message, "Upload Error");
return;
}
if (test == true)
{
MessageBox.Show("Success!");
toolStripStatusLabel1.Text = "Uploading testfile to server completes succesfully!";
return;
}
toolStripStatusLabel1.Text = "Uploading banlist to server completed succesfully!";
}
overload error
Page 1 of 11 Replies - 1007 Views - Last Post: 20 March 2010 - 10:43 AM
#1
overload error
Posted 20 March 2010 - 10:32 AM
heres a new problem. I am trying to test the connection to the server, but when i do i get a overload error.
Replies To: overload error
#2
Re: overload error
Posted 20 March 2010 - 10:43 AM
Quote
I am trying to test the connection to the server, but when i do i get a overload error.
Please elaborate on what an overload error is. Also, if possible, provide us with the stack trace that comes up from the error. If you're not getting one currently, put a break point on the catch that handles this (or make a general catch(Exception ex) statement) and when it breaks, push into it and find out what the exception member contains for stack trace.
I know what I'm trying to explain is incredibly hard to grasp if you haven't done it before. I'm sorry for that but unfortunately I can't currently think of a clearer way to explain this. Hopefully you can cope.
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|