begin process at 2010 02 10 04:56:12
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Astuces

 > UPLOAD FILE TO FTP SERVER

UPLOAD FILE TO FTP SERVER


 Description

Cliquez pour voir la capture en taille normale
c'est un simple source pour upload file to ftp server
program crée par bensoftchlef@gmail.com

alor vous pouvez ajouter des rebriques pour cette source pour crée un logiciel de transfaire des données ou dans une autre application software...

Source

  • using System;
  • using System.Collections.Generic;
  • using System.ComponentModel;
  • using System.Data;
  • using System.Net;
  • using System.IO;
  • using System.Drawing;
  • using System.Linq;
  • using System.Text;
  • using System.Windows.Forms;
  • namespace WindowsFormsApplication6
  • {
  • public partial class Form1 : Form
  • {
  • public Form1()
  • {
  • InitializeComponent();
  • }
  • private void Upload(string filename)
  • {
  • FileInfo fileInf = new FileInfo(filename);
  • string uri = uri = "ftp://" + textBox2.Text + "/" + fileInf.Name;
  • FtpWebRequest reqFTP;
  • // Create FtpWebRequest object from the Uri provided
  • reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + textBox2.Text + "/" + filename));
  • // Provide the WebPermission Credintials
  • reqFTP.Credentials = new NetworkCredential(textBox3.Text, maskedTextBox1.Text);
  • // By default KeepAlive is true, where the control connection is not closed
  • // after a command is executed.
  • reqFTP.KeepAlive = false;
  • // Specify the command to be executed.
  • reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
  • // Specify the data transfer type.
  • reqFTP.UseBinary = true;
  • // Notify the server about the size of the uploaded file
  • reqFTP.ContentLength = fileInf.Length;
  • // The buffer size is set to 2kb
  • int buffLength = 2048;
  • 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 = reqFTP.GetRequestStream();
  • // Read from the file stream 2kb at a time
  • contentLen = fs.Read(buff, 0, buffLength);
  • // Till Stream content ends
  • while (contentLen != 0)
  • {
  • // Write Content from the file stream to the FTP Upload Stream
  • strm.Write(buff, 0, contentLen);
  • contentLen = fs.Read(buff, 0, buffLength);
  • }
  • // Close the file stream and the Request Stream
  • strm.Close();
  • fs.Close();
  • }
  • catch (Exception ex)
  • {
  • MessageBox.Show(ex.Message, "Upload Error");
  • }
  • }
  • private void button1_Click(object sender, EventArgs e)
  • {
  • openFileDialog1.ShowDialog();
  • }
  • private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  • {
  • textBox1.Text = openFileDialog1.FileName;
  • }
  • private void button2_Click(object sender, EventArgs e)
  • {
  • Upload(textBox1.Text);
  • }
  • }
  • }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Upload(string filename)
        {

            FileInfo fileInf = new FileInfo(filename);

            string uri = uri = "ftp://" + textBox2.Text + "/" + fileInf.Name;

            FtpWebRequest reqFTP;

            // Create FtpWebRequest object from the Uri provided

            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + textBox2.Text + "/" + filename));

            // Provide the WebPermission Credintials

            reqFTP.Credentials = new NetworkCredential(textBox3.Text, maskedTextBox1.Text);

            // By default KeepAlive is true, where the control connection is not closed

            // after a command is executed.

            reqFTP.KeepAlive = false;

            // Specify the command to be executed.

            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

            // Specify the data transfer type.

            reqFTP.UseBinary = true;

            // Notify the server about the size of the uploaded file

            reqFTP.ContentLength = fileInf.Length;

            // The buffer size is set to 2kb

            int buffLength = 2048;

            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 = reqFTP.GetRequestStream();

                // Read from the file stream 2kb at a time

                contentLen = fs.Read(buff, 0, buffLength);

                // Till Stream content ends

                while (contentLen != 0)
                {

                    // Write Content from the file stream to the FTP Upload Stream

                    strm.Write(buff, 0, contentLen);

                    contentLen = fs.Read(buff, 0, buffLength);

                }

                // Close the file stream and the Request Stream

                strm.Close();

                fs.Close();

            }

            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Upload Error");

            }

        }
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog(); 
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            textBox1.Text = openFileDialog1.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Upload(textBox1.Text);
        }
    }
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources de la même categorie

Source avec une capture Source .NET (Dotnet) AJOUTER DES BYTES À UN EXECUTABLE par t0fx
Source .NET (Dotnet) COPIER/ COLLER DATAGRID (COPY/PASTE) par jamesbidon
Source avec Zip Source .NET (Dotnet) MECANISME DE SYNCHRONISATION DE THREAD - MONITOR, MUTEX, SEM... par jesusonline
Source .NET (Dotnet) EVENTHANDLERS GÉNÉRIQUES par ricklekebekoi
Source avec Zip Source .NET (Dotnet) TRAITER UN FOREACH EN PARALLÈLE par maitredede

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) [.NET 2]FREE FTP par leprov
Source avec Zip Source avec une capture Source .NET (Dotnet) GABFTP : UN CLIENT FTP BASIQUE AVEC INTERFACE GRAPHIQUE ÉCRI... par GabSoftware
Source avec Zip Source avec une capture Source .NET (Dotnet) SERVEUR FTP ET CLIENT GRAPHIQUE par devdoctor
Source .NET (Dotnet) ASP.NET - COMMENT FAIRE DU TRANSFERT FTP À PARTIR D'UNE APPL... par fabrice69

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

uploader un fichier dans ftp [ par sokotanic ] salut tout le monde, j'essai d'uploader un fichier dans ftp multimania mais il marche pas pourquoi. openFileDialog1.ShowDialog(); string Connexion FTP [ par CoChOnOu ] Salut à tous :)voilà, j'arrive tout droit du VB6 ... du coup j'avoue que je suis un peu beaucoup perdu avec le C# ...En fait j'aimerai savoir où je po recuperation de donnée [ par Online ] Bonjour, voila, j'ai réalisé un prog qui se connecte à un FTP via des commandes DOS, mais j'aimerais bien récupérer ls informations renvoyées par le s FTP et visual [ par meihua ] Voilà je suis en train de faire un programme où jarchive des données sur un site internet et je voulais savoir comment on fait?? Je sais qu'il faut pa envoie des données sur un ftp [ par meihua ] Voilà mon problème j'aimerai savoir comment fait on pour envoyer des données sur un ftp? uploader un fichier [ par Chino256 ] Salut,J'aurais voulu savoir s'il existe en C# un composant qui affiche dans la page un petit explorer, et va permettre de sélectionner un fichier en l HELP ME urgent!!!! envoie de fichier sur un ftp [ par shinevilkyo ] lu c encore moi,je deviens fou je trouve rien ds la lib msdn pour envoyer un fichier vers un ftp en c# si quelque sais dite le moi.si il n existe rien ftp [ par kedric ] bonjour je suis novice sur le c# et je voudrais faire un programe pour envoyer et recevoire des fichier par ftp sur ms dos le meme principe que http:/ FTP et C# [ par NonoSoft ] Bonjour,Je voulais savoir quel est le moyen le plus simple pour envoyer un fichier (une page HTML) sur un serveur FTP en C#.Merci d'avance@+ et bon su Upload [ par Bidou ] Bonjour,La question est simple : comment faire pour uploader un file sur un server, en sachantqu'il faut pouvoir s'identifier avec un username et pass


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,718 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales