Read/Write from a FTP source

Reading

using (var ftpClient = new WebClient
{
    Credentials = new NetworkCredential(_config.Upload_FtpUsername, _config.Upload_FtpPassword),
    Encoding = Encoding.UTF8
})
{
    Notify(this, new Message(string.Format("Attempting to Write {0} to the FTP Server", request)));
    var content = File.ReadAllText(request.SourceFilePath);
 
    //Upload the request
    ftpClient.UploadString(request.DestFilePath, content);
}

Writing

using (var ftpClient = new WebClient
{
    Credentials = new NetworkCredential(_config.Upload_FtpUsername, _config.Upload_FtpPassword)
})
{
    Notify(this, new Message("Attempting to Read from the FTP Server"));
    var ftpAddress = _config.TargetServer + @"/" + _config.TargetFilepath
        + @"/" + targetFolder + @"/" + targetSubFolder + @"/" + _config.TargetFilename;
 
    //Download the feed
    var readStr = ftpClient.DownloadString(ftpAddress);
    var newDoc = XDocument.Parse(readStr);
    return newDoc;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s