Downloads:
Features:
- Upload files to FTP server
C# Source Code:
- Main.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
using System; using System.ComponentModel; using System.IO; using System.Net; using System.Windows.Forms; namespace FTP_Uploader { public partial class Main : Form { public Main() { InitializeComponent(); } private void Main_Load(object sender, EventArgs e) { } #region Upload To Ftp private void uploadFile(string FTPAddress, string filePath, string username, string password) { FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + Path.GetFileName(filePath)); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); request.UsePassive = true; request.UseBinary = true; request.KeepAlive = false; FileStream stream = File.OpenRead(filePath); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Close(); Stream reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); reqStream.Close(); } private void btnUpload_Click(object sender, EventArgs e) { if ( txtDirectory.Text != "") { groupBox1.Enabled = false; pictureBox1.Show(); backgroundWorker1.RunWorkerAsync(); } else { MessageBox.Show("Choose file to upload first !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { string ftpUser = @"" + txtUserName.Text; string ftpPass = txtPassword.Text; string ftpAddress = @"" + txtFTP.Text; string filePath = txtDirectory.Text; uploadFile(ftpAddress, filePath, ftpUser, ftpPass); pictureBox1.Hide(); groupBox1.Enabled = true; MessageBox.Show("Uploaded Successfully !", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } catch { pictureBox1.Hide(); groupBox1.Enabled = true; MessageBox.Show("Unknown Error !\nPlease try again later !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } } #endregion private void btnDirectory_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); DialogResult dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { txtDirectory.Text = ofd.FileName; } } } } |
Screenshots:
Similar Apps:
Unknown
Contact: