"upload chunked file in ftp using c#" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "upload chunked file in ftp using c#" answered properly. Developers are finding an appropriate answer about upload chunked file in ftp using c# related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like upload chunked file in ftp using c#. Enter your desired code related query in the search bar and get every piece of information about C# code related question on upload chunked file in ftp using c#.
upload chunked file in ftp using c#
System.IO.FileInfo _FileInfo = new System.IO.FileInfo(_FileName);
// Create FtpWebRequest object from the Uri provided
System.Net.FtpWebRequest _FtpWebRequest = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(new Uri(_UploadPath));
// Provide the WebPermission Credintials
_FtpWebRequest.Credentials = new System.Net.NetworkCredential(_FTPUser, _FTPPass);
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
_FtpWebRequest.KeepAlive = false;
// set timeout for 20 seconds
_FtpWebRequest.Timeout = 20000;
// Specify the command to be executed.
_FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
// Specify the data transfer type.
_FtpWebRequest.UseBinary = true;
// Notify the server about the size of the uploaded file
_FtpWebRequest.ContentLength = _FileInfo.Length;
// The buffer size is set to 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
System.IO.FileStream _FileStream = _FileInfo.OpenRead();
try
{
// Stream to which the file to be upload is written
System.IO.Stream _Stream = _FtpWebRequest.GetRequestStream();
// Read from the file stream 2kb at a time
int contentLen = _FileStream.Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
_Stream.Write(buff, 0, contentLen);
contentLen = _FileStream.Read(buff, 0, buffLength);
}
// Close the file stream and the Request Stream
_Stream.Close();
_Stream.Dispose();
_FileStream.Close();
_FileStream.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
All those coders who are working on the C# based application and are stuck on upload chunked file in ftp using c# can get a collection of related answers to their query. Programmers need to enter their query on upload chunked file in ftp using c# related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about upload chunked file in ftp using c# for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of upload chunked file in ftp using c# while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "upload chunked file in ftp using c#". Visit this developer's friendly online web community, CodeProZone, and get your queries like upload chunked file in ftp using c# resolved professionally and stay updated to the latest C# updates.