abburi chowdary

abburi chowdary

  • NA
  • 60
  • 15k

How to upload files and encrypt in FTP server

May 7 2018 10:40 PM
I have written below code to copy file from local system to ftp server , similarly i need to select multiple files and upload them in server . While i upload the files it should be converted as encrypted files, any suggestions, i have written code for encryption also.
  1. public class WebRequestGetExample  
  2. {  
  3. public static void Main ()  
  4. {  
  5. // Get the object used to communicate with the server.  
  6. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.1....../ftp.txt"); request.Method =WebRequestMethods.Ftp.UploadFile;  
  7. // This example assumes the FTP site uses anonymous logon.  
  8. request.Credentials = new NetworkCredential("username""password");  
  9. // Copy the contents of the file to the request stream.  
  10. byte[] fileContents;  
  11. using (StreamReader sourceStream = new StreamReader("E:\\Anusha\\ftp.txt"))  
  12. {  
  13. fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());  
  14. }  
  15. request.ContentLength = fileContents.Length;  
  16. using (Stream requestStream = request.GetRequestStream())  
  17. {  
  18. requestStream.Write(fileContents, 0, fileContents.Length);  
  19. }  
  20. using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())  
  21. {  
  22. Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);  
  23. }  
  24. }  
  25. }