Introduction:
In this article,i am going to explain about how to copying/Transfering files from local machine to netftp server.
Main:
Sample Code,
string netftpUserID1 = "";//netftp UserId
string netftpPassword1=""//netftp password
FileInfo fileInf = new FileInfo(C:\Sample.txt);
string uri = "ftp://" + netftp.netprogramminghelp.com + "/" + fileInf.Name;
netftpWebRequest reqnetftp;
// Create netftpWebRequest object from the Uri provided
reqnetftp = (netftpWebRequest)netftpWebRequest.Create
(new Uri("netftp://" + netftp.netprogramminghelp.com + "/" + fileInf.Name));
// Provide the WebPermission Credintials
reqnetftp.Credentials = new NetworkCredential(netftpUserID1, netftpPassword1);
// By default KeepAlive is true, where the control connection
// is not closed after a command is executed.
reqnetftp.KeepAlive = false;
// Specify the command to be executed.
reqnetftp.Method = WebRequestMethods.netftp.UploadFile;
// Specify the data transfer type.
reqnetftp.UseBinary = true;
// Notify the server about the size of the uploaded file
reqnetftp.ContentLength = fileInf.Length;
int buffLength = 500447300;
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 = reqnetftp.GetRequestStream();
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
// Till Stream content endswhile (contentLen != 0)
{
// Write Content from the file stream to the netftp Upload
// Stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
strm.Close();
fs.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
string netftpUserID1 = "";//netftp UserId string netftpPassword1=""//netftp password FileInfo fileInf = new FileInfo(C:\Sample.txt); string uri = "ftp://" + netftp.netprogramminghelp.com + "/" + fileInf.Name; netftpWebRequest reqnetftp; // Create netftpWebRequest object from the Uri provided reqnetftp = (netftpWebRequest)netftpWebRequest.Create (new Uri("netftp://" + netftp.netprogramminghelp.com + "/" + fileInf.Name)); // Provide the WebPermission Credintials reqnetftp.Credentials = new NetworkCredential(netftpUserID1, netftpPassword1); // By default KeepAlive is true, where the control connection // is not closed after a command is executed. reqnetftp.KeepAlive = false; // Specify the command to be executed. reqnetftp.Method = WebRequestMethods.netftp.UploadFile; // Specify the data transfer type. reqnetftp.UseBinary = true; // Notify the server about the size of the uploaded file reqnetftp.ContentLength = fileInf.Length; int buffLength = 500447300; 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 = reqnetftp.GetRequestStream(); // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); // Till Stream content endswhile (contentLen != 0) { // Write Content from the file stream to the netftp Upload // Stream strm.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); } strm.Close(); fs.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } |
Conclusion:
Hope this helps,
Happy Coding.
Great site. A lot of useful information here. I’m sending it to some friends!
Aamazing, just purely amazing performance
Hi, I do not usually post feedback on blogs, as I prefer to learn only. But I find the article that you have written earlier has very insightful data, and I find it very informational. Anyway, I am questioning whether or not you might be open for hyperlink trade, as I hope that we are able to agree on a mutual link change agreement. Hope to hear a optimistic reply from you, and have a fantastic day!
I randomly browse blogs on the internet, and I discover your article to be very informational. I’ve already bookmark it on my browser, so that I can view your blog publish once more later. Additionally, I am questioning whether or not your blog is open for link exchange, as I actually wish to trade hyperlinks with you. I do not normally do this, but I hope that we can have a mutual hyperlink exchange. Let me know and have an important day!