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();
}