string uri="www.abc.com";
string file = "ful path of local file";
string usename="usename";
string password="password";
string DName="Server Directory Name";
public void UploadFile(string uri, string file, string usename, string password, string DName)
{
string fullpath = "ftp://ftp." + uri + "/" + uri + "/wwwroot/" + DName + "/";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(fullpath + fileToUpload.FileName));
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(usename, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
request.Timeout = 100000;
//Load the file
FileStream stream = File.OpenRead(file);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
lblmsg.Visible = true;
lblmsg.Text = "File upload successfully";
}
string file = "ful path of local file";
string usename="usename";
string password="password";
string DName="Server Directory Name";
public void UploadFile(string uri, string file, string usename, string password, string DName)
{
string fullpath = "ftp://ftp." + uri + "/" + uri + "/wwwroot/" + DName + "/";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(fullpath + fileToUpload.FileName));
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(usename, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
request.Timeout = 100000;
//Load the file
FileStream stream = File.OpenRead(file);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
lblmsg.Visible = true;
lblmsg.Text = "File upload successfully";
}
No comments:
Post a Comment