Avec OpenNETCF voila ce que je fais mais mon problème c'est que je n'arrives pas a fair mon upload...
Code:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using OpenNETCF.Net.Ftp;
using System.Net;
namespace ftpmobile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.MinimizeBox = false;
}
private void ftpup(string FTPAddress, string filePath, string username, string password)
{
FtpWebRequest ftpRequest;
//FtpWebResponse ftpResponse;
string fileName = Path.GetFileName(filePath);
FileInfo oFile = new FileInfo(fileName);
try
{
FtpRequestCreator creator = new FtpRequestCreator();
WebRequest.RegisterPrefix("ftp:", creator);
// Building our URI object
Uri testUri;
if ("192.168.0.189".IndexOf("ftp:") != 0)
{
testUri = new Uri(FTPAddress);
}
else
testUri = new Uri(FTPAddress);
//Settings required to establish a connection with the server
MessageBox.Show(testUri + oFile.Name, "create");
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(testUri + oFile.Name);
//ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.KeepAlive = false;
ftpRequest.Proxy = null;
ftpRequest.Binary = true;
ftpRequest.Credentials = new NetworkCredential(username, password);
//Selection of file to be uploaded
byte[] fileContents = new byte[oFile.Length];
MessageBox.Show(oFile.Length.ToString(), "lenght");
//will destroy the object immediately after being used
using (FileStream fr = oFile.OpenRead())
{
fr.Read(fileContents, 0,Convert.ToInt32(oFile.Length));
}
using (Stream writer = ftpRequest.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
}
MessageBox.Show("Successfully uploaded.");
ftpRequest = null;
}
catch (WebException webex)
{
MessageBox.Show(webex.ToString(), "Error");
}
}
private void button1_Click(object sender, EventArgs e)
{
ftpup("ftp://150.0.0.1/", "/rw420.doc", "dl", "dl");
}
}
}
merci d'avance