I have to upload a file to an ftp server (local host 127.0.0.1) but before I have to make a backup of that file (with a name different from the original) from where I upload it, this second part is what I can not do . I leave what I have until now:
//Upload a file from a X Path to the FTP Server and backup of the file
public static void FtpUploadExeAndBk(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;
//Hacer el backup y que se quede en la carpeta local (renombrar) ?????
StreamReader sourceStreamBk = new StreamReader(@"C:\Projects\Configurator.exe");
sourceStreamBk.ToString=sourceStreamBk.ToString.Concat("_bk");
//??????
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();
}