begin process at 2012 02 07 08:56:17
  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 Zip Source .NET (Dotnet) DIFFÉRENTIELLE ENTRE DEUX COLLECTION par morphey_83
Source avec Zip Source avec une capture Source .NET (Dotnet) RICHTEXTBOX POUR COLORATION SYNTAXIQUE EN TEMPS REEL par Renfield
Source avec Zip Source avec une capture Source .NET (Dotnet) TRANSFORMER UN PROGRAMME EN SERVICE par xavh44
Source avec Zip Source .NET (Dotnet) [C# ET T4] TEMPLATE DE VIEW MODEL POUR LE PATTERN MVVM par Kite37
Source .NET (Dotnet) EXEMPLE D'UTILISATION D'UN OCX SANS DECLARATION PREALABLE DA... par yohan49

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture FTPROG - CLIENT FTP TRÈS BASIQUE par Jukuso
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 c# création de dossier sur un serveur ftp [ par Perecastorr ] Bonjour, Alors voila, j'ai une petite classe qui gère les upload et download asynchrone avec liste d'attente grâce a la classe Web Client en c#, tout FTP - WebClient avec plusieurs fichiers à télécharger [ par julien040807 ] Bonjour tout le monde. J'ai une petite question à propos des objets webclient ... Enfaite, je lance une connexion à mon serveur FTP et je demande au FTP - Déclenchement sécurité Anti brute forcing [ par Perecastorr ] Bonjour, J'ai créer une petite application qui utilise des transfert type ftp grâce a la classe FtpWebRequest. Régulièrement, le serveur se bloque po Télécharger tous les fichiers d'un répertoire - FtpWebRequest [ par julien040807 ] Bonjour, Enfaite j'ai un petit soucis, je veux télécharger tous les fichiers présents dans un répertoire spécifique sur un serveur FTP. Pour ce faire L'exception ArgumentException n'a pas été gérée [ par Dodey ] Bonjour, Donc je suis en train de coder une application en C# pour récupérer un fichier sur un serveur FTP a partir d'un pocket PC. Je développe sous PROBLEME : Connexion serveur ftp via proxy ftp [ par harry_potter_57 ] Bonjour à tous, Voici maintenant une semaine que je bloquue sur un problème de connexion à mon serveur ftp via proxy ftp. J'utilise pour celà FTPWebR FTP connéction [ par chaouki1588 ] je travail sur visual studio 2010 mon projet consiste a faire une ptite aplication qui permet de consulter les fax sur un serveur sachant que le type Téléchargement FTP... 0D 0A [ par Djzlouk ] Bonjour, J'ai un serveur FTP qui contient un ZIP. Je souhaite tout simplement le télécharger sur ma machine et le dézipper. Pour cela, je fais : 1 Microsoft Synchronisation Framework [ par MadMatt67 ] bonjour, Je souhaiterais utiliser le framework Sync de Microsoft afin de synchroniser un serveur FTP avec un dossier en local ! Cependant, je rencont


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

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 : 1,482 sec (4)

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