I have created a console application to send an upload of job postings to monster.com the requirements of the appliction are to send a JSon feed of each open position via ftp to them. To handle this i created 3 classes. the first class is the JobPostings which has 8 properties and 1 method (GetPostings), then there is the Feed class which has 5 properties and no methods and lastly the JobFeed class which has 1 property. Once it creates the json feed it is saved to a directory on the computer and then I create an instance of the WebClient class to upload to Monster. Right now I am telling it to write to the console after it completes making the file and then after uploading. Which it is doing , but if I use another program to look in the ftp directory it is empty. By looking at my code can you tell me what I have done wrong
Here is my code
Here is a link to the monster specs https://partner.monster.com/job-ads-non-duration
Here is my code
default program:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.IO;
using System.Net;
using System.Net.Mail;
namespace MonsterOrganicJobs
{
class Program
{
//static void Main(string[] args)
static void Main()
{
string today = DateTime.Today.ToShortDateString();
string path = @"X:\MonsterFeed\"; //@"E:\WebPages\MonsterFeed\"; <-- once working properly we will use this directory
string fileName = today.Replace("/", "-") + ".json";
try
{
//Get the postings and serialize as json
JobPosting jobPosting = new JobPosting();
List<JobPosting> myList = jobPosting.GetPostings();
string jsonString = JsonSerializer.Serialize(myList);
//create the json feed
Feed feed = new Feed
{
isfullfeed = true,
islast = true,
part = 1,
provider = "Company name here",
jobs = jsonString
};
string myfeed = JsonSerializer.Serialize(feed);
//create the json jobfeed
JobFeed jobFeed = new JobFeed
{
jobfeed = myfeed
};
byte[] jobfeed = JsonSerializer.SerializeToUtf8Bytes(jobFeed);
string thefeed = Encoding.UTF8.GetString(jobfeed);
string FileLocation = path + fileName;
//Create the file
File.WriteAllText(FileLocation, thefeed);
Console.WriteLine("file saved to " + FileLocation);
//send to monster using ftp
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential("myID", "MyPassword");
client.UploadFile("ftp.monster.com", WebRequestMethods.Ftp.UploadFile, FileLocation);
Console.WriteLine("File uploaded.");
Console.ReadKey();
}
}
catch (Exception e)
{
SendAnEmail(e.ToString(), "Error Uploading file to Monster");
Console.WriteLine(e);
Console.ReadKey();
}
}
public static void SendAnEmail(string message, string subject)
{
using (MailMessage msg = new MailMessage("Sending_Email_Address", "mj_Email_Address"))
{
msg.Subject = subject;
msg.Body = message;
msg.BodyEncoding = System.Text.UTF8Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.Default;
msg.IsBodyHtml = true;
using (var smtp = new SmtpClient("mail.CompanyName.net"))
{
NetworkCredential networkCredential = new NetworkCredential("Sending_Email_Address", "Email_password");
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCredential;
smtp.Send(msg);
}
}
}
}
}
Here is a link to the monster specs https://partner.monster.com/job-ads-non-duration