FTP

Top  Previous  Next

Apenas para Android (fazer injeção de dependência). Permissão: Internet

 

 string arquivo_local = "/mnt/sdcard/Market/backup_banco.db3";

 
 string ftpHost = "ftp.market.com.br";
 string ftpUser = "publico";
 string ftpPassword = "pub.market";
 string ftpfullpath = "ftp://market.com.br/Junior/banco.db3";
 
 FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
 
 // userid and password for the ftp server  
 ftp.Credentials = new NetworkCredential(ftpUser, ftpPassword);
 ftp.KeepAlive = true;
 ftp.UseBinary = true;
 ftp.Method = WebRequestMethods.Ftp.UploadFile;
 
 FileStream fs = File.OpenRead(arquivo_local);
 byte[] buffer = new byte[fs.Length];
 fs.Read(buffer, 0, buffer.Length);
 fs.Close();
 
 Stream ftpstream = ftp.GetRequestStream();
 ftpstream.Write(buffer, 0, buffer.Length);
 ftpstream.Close();
 ftpstream.Flush();