Solved

Store file creation attribute in a string array for later use.

Posted on 2010-09-16
5
433 Views
Last Modified: 2012-06-27
I am pulling multiple files from an FTP site, and when the files are local, I am storing them in separate folders with the current date and time stamp. What I need in addition to that is a minor function that will query the files while they are still on the ftp site for their file creation date. I will be using this creation date to rename the files.

I will show some sample code to help me get started.
string[] auditnameList = FTP.getFileList("*");

            foreach (string auditN in auditnameList)
            {
                string[] creationDate = File.GetCreationTime(auditN);
            }

Open in new window

0
Comment
Question by:Abacus IT
  • 3
5 Comments
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33693598
Not very clear though. File.GetCreationTime wouldn't work in your case?

I think when File is downloaded locally the CreationTime on FTP is different than on local. You can only refer to local time.

I'm still confused what you're asking here.
0
 
LVL 1

Author Comment

by:Abacus IT
ID: 33694608
The main reason for the question was because when the files are created on the FTP site, there is a chance that the contents of the files from 2 different days could have the same date when pulled locally. On the site itself I can see the time of the creation, which helps me when I rename them manually. When my code is pulling and extracting these files automatically, it will only get the creation date of right when the files are pulled, which could cause issues when processing these files.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 125 total points
ID: 33696766
What are you using for an FTP client in your C# code?
Here's a simple example using an FtpWebRequest to list the details of a remote directory; this is connecting to a remote Microsoft FTP server, I'm not sure if the response format is guarunteed between diferrent FTP vendors...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp.server.com/");
			ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
			ftpRequest.Credentials = new NetworkCredential("user", "password");
			FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
			Stream responseStream = ftpResponse.GetResponseStream();
			StreamReader responseReader = new StreamReader(responseStream);

			while (!responseReader.EndOfStream)
			{
				string[] entryDetails = responseReader.ReadLine().Split(new char[] { ' ' }, 4, StringSplitOptions.RemoveEmptyEntries);

				DateTime modified = DateTime.Parse(entryDetails[0] + " " + entryDetails[1]);

				bool isDir = false;
				int size = -1;
				if (entryDetails[2] == "<DIR>")
					isDir = true;
				else
					size = Int32.Parse(entryDetails[2]);

				string name = entryDetails[3];

				Console.WriteLine(String.Format(
					"Entry name: {0}\r\nIs directory: {1}\r\nFile Size: {2}\r\nModification Date/Time: {3}\r\n",
					name, isDir, size, modified));
			}
			Console.ReadKey();
		}
	}
}

Open in new window

0
 
LVL 1

Author Comment

by:Abacus IT
ID: 33701383
I am trying this addition to my code now, and seeing if I can modify it a little to fit some specifications. It seems to work so far, still doing testing.
0
 
LVL 1

Author Comment

by:Abacus IT
ID: 33701770
This code will work perfectly for what I need. The only outstanding thing is, you have this written as a loop. So, what I need is to store 2 of the entry details in a variable to be used later then cleared out, then allow your loop to repopulate the variable for the next file name.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Wav problem 4 26
Where can I ask about my ASP.NET MVC project? 6 36
Example works but why do I need to click twice on button 4 41
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question