Skip to main content
se añadieron 14 caracteres en el cuerpo
Origen Enlace
sstan
  • 16.9k
  • 2
  • 24
  • 48

Tengo que copiar un .exe desde una carpeta local y moverlo a un servidor ftp, al hacerlo, el .exe pasa a ser un archivo de tamaño mayor y no me deja ejecutarlo. Este es el código que tengo:

public static void FtpBkAndUploadNewVersion(string direccionIP, string username, string password) { // Get the object used to communicate with the server Uri uri = new Uri(string.Concat("ftp://", direccionIP, "/Configurator.exe")); FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(uri); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri); request.Method = WebRequestMethods.Ftp.UploadFile;

public static void FtpBkAndUploadNewVersion(string direccionIP, string username, string password)
    {
        // Get the object used to communicate with the server
        Uri uri = new Uri(string.Concat("ftp://", direccionIP, "/Configurator.exe"));
        FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(uri);
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
        request.Method = WebRequestMethods.Ftp.UploadFile;     

        // This example assumes the FTP site uses anonymous logon
        request.Credentials = new NetworkCredential(username, password);

        // Copy the contents of the file to the request stream
        StreamReader sourceStream = new StreamReader(@"C:\Projects\Configurator.exe");
        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

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

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();  
    }  

Tengo que copiar un .exe desde una carpeta local y moverlo a un servidor ftp, al hacerlo, el .exe pasa a ser un archivo de tamaño mayor y no me deja ejecutarlo. Este es el código que tengo:

public static void FtpBkAndUploadNewVersion(string direccionIP, string username, string password) { // Get the object used to communicate with the server Uri uri = new Uri(string.Concat("ftp://", direccionIP, "/Configurator.exe")); FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(uri); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri); request.Method = WebRequestMethods.Ftp.UploadFile;

        // This example assumes the FTP site uses anonymous logon
        request.Credentials = new NetworkCredential(username, password);

        // Copy the contents of the file to the request stream
        StreamReader sourceStream = new StreamReader(@"C:\Projects\Configurator.exe");
        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

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

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();  
    }  

Tengo que copiar un .exe desde una carpeta local y moverlo a un servidor ftp, al hacerlo, el .exe pasa a ser un archivo de tamaño mayor y no me deja ejecutarlo. Este es el código que tengo:

public static void FtpBkAndUploadNewVersion(string direccionIP, string username, string password)
    {
        // Get the object used to communicate with the server
        Uri uri = new Uri(string.Concat("ftp://", direccionIP, "/Configurator.exe"));
        FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(uri);
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
        request.Method = WebRequestMethods.Ftp.UploadFile;     

        // This example assumes the FTP site uses anonymous logon
        request.Credentials = new NetworkCredential(username, password);

        // Copy the contents of the file to the request stream
        StreamReader sourceStream = new StreamReader(@"C:\Projects\Configurator.exe");
        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

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

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();  
    }  
Origen Enlace
LopezAi
  • 173
  • 1
  • 15

problema al copiar fichero desde local y moverlo a servidor ftp c#

Tengo que copiar un .exe desde una carpeta local y moverlo a un servidor ftp, al hacerlo, el .exe pasa a ser un archivo de tamaño mayor y no me deja ejecutarlo. Este es el código que tengo:

public static void FtpBkAndUploadNewVersion(string direccionIP, string username, string password) { // Get the object used to communicate with the server Uri uri = new Uri(string.Concat("ftp://", direccionIP, "/Configurator.exe")); FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create(uri); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri); request.Method = WebRequestMethods.Ftp.UploadFile;

        // This example assumes the FTP site uses anonymous logon
        request.Credentials = new NetworkCredential(username, password);

        // Copy the contents of the file to the request stream
        StreamReader sourceStream = new StreamReader(@"C:\Projects\Configurator.exe");
        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

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

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();  
    }