Get the Flash Player to see this content.
دانلود ویدیو آپلود فایل با سی شارپ (105)
به این مطلب توجه کنید که اگر از cpanel استفاده می کنید باید در آدرس آپلود فایل “public_html” قید شود. کدهای ویدیو را برای راحتی کار٬ نوشته ام.
using System.IO; using System.Net;
private void btnUpload_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
UploadFile(ofd.FileName);
}
private void UploadFile(string FileAddress)
{
try
{
FileInfo fi = new FileInfo(FileAddress);
FtpWebRequest req = (FtpWebRequest)WebRequest.Create("Your address" + fi.Name);
req.Method = WebRequestMethods.Ftp.UploadFile;
req.Credentials = new NetworkCredential("Your ftp username", "Your ftp password");
Stream ftpStream = req.GetRequestStream();
FileStream fs = File.OpenRead(FileAddress);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;
do
{
bytesRead = fs.Read(buffer, 0, length);
ftpStream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
fs.Close();
ftpStream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
نوشته های مرتبط
