Accueil > > > UPLOAD FILE TO FTP SERVER
UPLOAD FILE TO FTP SERVER
Information sur la source
Description
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);
}
}
}
Sources de la même categorie
Commentaires et avis
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
|
Derniers Blogs
[TECHDAYS2012] OUI J'Y SERAI![TECHDAYS2012] OUI J'Y SERAI! par JeremyJeanson
Bonsoir, Certes, je l'annonce avec un peu de retard, mais je serai effectivement au Techdays demain. Comme l'an dernier, je participerai au programme ATE (Ask The Expert). Si vous avez des questions Workflow, WCF, AppFabric ou plus généralement .net, n'hé...
Cliquez pour lire la suite de l'article par JeremyJeanson TFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICESTFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICES par vfabing
Afin de s'assurer du bon fonctionnement des différentes synchronisations effectuées par les TFS Integration Tools, 2 rapports sont présents dès l'installation. Il suffit alors d'effectuer les manipulations suivantes pour pouvoir les visualiser : Loca...
Cliquez pour lire la suite de l'article par vfabing CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|