Divyang Desai

Divyang Desai

  • 278
  • 6.2k
  • 520.5k

How to save json file to the FTP location without saving

Apr 20 2018 5:53 AM
Hi,
 
I'm trying to create and store Json file to the server each time with different name(using windows services), without saving on my application it should directly store to FTP location.
 
I have tried as following 
 
  1. string ftpAddress = "http://dev-web/hrm/assets/";  
  2. string username = "developer";  
  3. string password = "123";  
  4.   
  5. WebRequest request = WebRequest.Create(ftpAddress);  
  6. request.Method = WebRequestMethods.Ftp.UploadFile;  
  7. request.Credentials = new NetworkCredential(username, password);  
  8.   
  9. string currentDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);  
  10.   
  11. using (var sw = new StreamWriter(request.GetRequestStream()))  
  12. {  
  13.     sw.Write(jsondata);  
  14.     sw.Flush();  
  15.     sw.Close();  
  16. }  
 This code doesn't work and neither giving me any error. I just want to know how to give particular name to the files.