|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI wrote this utility when I found myself having to repeatedly edit files for a Web site and then use an FTP client to upload the changes. Since I was spending my time editing images, I had to switch between multiple programs and then perform multiple steps to get the changed files uploaded. This made me want a simpler way.
Using FtpPublisher
Once your FTP connection information has been entered, To further increase the efficiency of the application, it can create a file association with its own file type. This is done by running the InstallUtil on the executable. If this is done, uploading your changes to an FTP site is as simple as double clicking the configuration file and watching it work. The CodeFTPAll FTP functions come from edtFTPnet. I didn't use .NET 2.0's File SynchronizationEvery file entry in the configuration contains a path and a DateTime stamp for when that file was uploaded last. It decides to upload if the file has been modified since it last wrote the stamp. I chose this method instead of getting the DateTime from the FTP because I wanted these local files to be the master copies. if (File.GetLastWriteTime(item.Path) > item.LastUpload)
Thread Synchronization with Anonymous MethodsThe execution mode has its own UI. To keep that UI responsive, I have a progressBarMain.Invoke((MethodInvoker)delegate() { });
As I was coding, I wondered if there was another way to ensure the updates were run on the correct thread. This is where It works by getting a reference to the current thread when the SynchronizationContext context = SynchronizationContext.Current;
Then, inside the background thread, a call to its context.Send(delegate(object state) { }, null);
InstallerSetting up file associations is an easy thing to do, but some people might not know the details of how it's done. So here is an example: public static void PerformInstall(string path)
{
if (File.Exists(path))
{
RegistryKey key = Registry.ClassesRoot.CreateSubKey(".cFtp");
key.SetValue("", "cFtpFileType", RegistryValueKind.String);
key.SetValue("Content Type", "text/xml", RegistryValueKind.String);
key = Registry.ClassesRoot.CreateSubKey("cFtpFileType");
key.SetValue("", "Ftp Publisher Configuration",
RegistryValueKind.String);
RegistryKey icon = key.CreateSubKey("DefaultIcon");
icon.SetValue("", string.Format("{0}",
Path.Combine(Path.GetDirectoryName(path), "Icon.ico")),
RegistryValueKind.String);
RegistryKey cmd = key.CreateSubKey("shell\\open\\command");
cmd.SetValue("", string.Format("\"{0}\" \"%1\"", path),
RegistryValueKind.String);
}
}
Notes
History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||