none
Upload de arquivo XML RRS feed

  • Pergunta

  • Olá Srs,

     

    Tenho um WS, e preciso fazer upload de arquivos XML p/ minha area FTP,

     

    FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.neo.eti.br/trans");

    request.Method = WebRequestMethods.Ftp.UploadFile;

    request.Credentials = new NetworkCredential("***", "*********");

    StreamReader fonteFile = new StreamReader(nomeDoArquivoEExtensao);

    Byte[] fileContent = Encoding.UTF8.GetBytes(fonteFile.ReadToEnd());

    fonteFile.Close();

    request.ContentLength = fileContent.Length;

    Stream requestStream = request.GetRequestStream();

    requestStream.Write(fileContent, 0, fileContent.Length);

    requestStream.Close();

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

    response.Close();

     

    Estou tentando fazer + ou - isso, se ouver um meio + simples gostaria de ssaber.

    Ou receber mais orientações.

     

    Adson

    terça-feira, 12 de fevereiro de 2008 14:08

Respostas

  • http://www.example-code.com/csharp/ftp.asp

    http://www.example-code.com/csharp/ftp_upload.asp

     

    bool success;

    //  Any string unlocks the component for the 1st 30-days.
    success = ftp.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        MessageBox.Show(ftp.LastErrorText);
        return;
    }

    ftp.Hostname = "ftp.chilkatsoft.com";
    ftp.Username = "****";
    ftp.Password = "****";

    //  The default data transfer mode is "Active" as opposed to "Passive".

    //  Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        MessageBox.Show(ftp.LastErrorText);
        return;
    }

    //  Change to the remote directory where the file will be uploaded.
    success = ftp.ChangeRemoteDir("junk");
    if (success != true) {
        MessageBox.Show(ftp.LastErrorText);
        return;
    }

    //  Upload a file.
    string localFilename;
    localFilename = "hamlet.xml";
    string remoteFilename;
    remoteFilename = "hamlet.xml";

    success = ftp.PutFile(localFilename,remoteFilename);
    if (success != true) {
        MessageBox.Show(ftp.LastErrorText);
        return;
    }

    ftp.Disconnect();

    MessageBox.Show("File Uploaded!");

    terça-feira, 12 de fevereiro de 2008 20:12