|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
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
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
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
Connexion à un serveur ftp [ par Fildomen ]
salutje veux faire un prog qui se connecte à un serveur ftp (comme "ftp.multimania.fr"), et j'efface un fichier la dedans nomé "xx.txt", et je upload
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|