none
Upload em outro servidor RRS feed

  • Pergunta

  • Tenho meu sistema publicado no iis no servidor X, preciso fazer um upload no servidor Y, já tentei desses dois jeitos porém sem sucesso, alguma ideia de como fazer isso?

    //exemplo 1
    Uri url = new Uri("http://10.3.4.67/upload/pdf/" + arq);
    AsyncFileUpload1.SaveAs(url.AbsoluteUri);
    
    //exemplo 2
    using (WebClient client = new WebClient())
    {
      Uri url = new Uri(url.AbsoluteUri);
      client.Credentials = CredentialCache.DefaultCredentials;
      client.Headers.Add("Content-Type", "application/x-www-  form-urlencoded");
      client.UploadData(url, "PUT", postData);
    }

    sexta-feira, 8 de fevereiro de 2013 11:16

Respostas

  •             try
                {
                    string uploadUrl = @"ftp://10.3.4.67/upload/pdf/";
                    string uploadFileName = fileToUpload.FileName;
    
                    Stream streamObj = fileToUpload.InputStream;
                    Byte[] buffer = new Byte[fileToUpload.ContentLength];
                    streamObj.Read(buffer, 0, buffer.Length);
                    streamObj.Close();
                    streamObj = null;
    
                    string ftpUrl = string.Format("{0}/{1}", uploadUrl, uploadFileName);
                    FtpWebRequest requestObj = FtpWebRequest.Create(ftpUrl) as FtpWebRequest;
                    requestObj.Method = WebRequestMethods.Ftp.UploadFile;
                    requestObj.Credentials = new NetworkCredential("usuario", "senha");
                    Stream requestStream = requestObj.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Flush();
                    requestStream.Close();
                    requestObj = null;
    
                    return true;
                }
                catch
                {
                    return false;
                }


    Leonardo Garcia
    pensouweb@hotmail.com

    • Marcado como Resposta Pedro Ogm sexta-feira, 8 de fevereiro de 2013 12:41
    sexta-feira, 8 de fevereiro de 2013 11:41