[译]EasyFtp 1.3.2(用于应用程序)
By robot-v1.0
本文链接 https://www.kyfws.com/applications/easyftp-1-3-2-for-applications-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 12 分钟阅读 - 5809 个词 阅读量 0[译]EasyFtp 1.3.2(用于应用程序)
原文地址:https://www.codeproject.com/Articles/6193/EasyFtp-1-3-2-for-Applications
原文作者:.dan.g.
译文由本站 robot-v1.0 翻译
前言
A ‘drop-in’ FTP solution for applications providing a full GUI, extended commandline options and no resource files. Use standalone or compiled into your own app.
适用于应用程序的"嵌入式" FTP解决方案,提供完整的GUI,扩展的命令行选项且无资源文件.使用独立的或编译成自己的应用程序.
介绍(Introduction)
我记得当我第一次开始使用Internet时(1993年在14400 USR sportster调制解调器上使用Winsock)时,它变得多么令人兴奋,不再让我在计算机上感到孤立.尽管如此,我仍然花了10年左右的时间才开始真正地为它编程-没有人说我在走路之前就跑了!它实际上仅是由于写作而产生的(I remember when I first started using the internet (in 1993 using Winsock on a 14400 USR sportster modem) about just how exciting it was to no longer feel isolated on my computer. Nevertheless, it has still taken me 10 years or so to actually start programming for it - no-one ever said I ran before I could walk! And it has really only come about as a result of writing) 待办事项清单(ToDoList) ,一个基于XML的"任务列表",也发布在CodeProject上.(, an XML ‘based’ task-list-thingy, also posted on CodeProject.)
我之所以决定将XML作为数据格式,正是因为可以将XML上传到我的网站并使用JavaScript进行处理,更不用说XSL转换以及由此带来的大量报告机会了.(I had decided on XML as the data format precisely because it could be uploaded to my web site and processed using JavaScript, to say nothing of XSL transforms and the myriad of opportunities this presents for reporting.)
但是,我仍然每天如何进行此上传?使用FTP实用程序就是这样.(And yet how was I still doing this uploading on a day-today basis? Using an FTP utility, that’s how.)
您可能会(或可能不会)问:“那又有什么问题呢?"(“And what’s wrong with that”, you may (or you may not) ask?)
从严格的功能角度来看,没有什么比这个过程经常让我感到震惊的是如此不连贯:将文档保存在一个应用程序中,然后启动一个单独的实用程序来传输文件,只是大声地对我大喊大叫.(Nothing, from a strictly functional perspective, it’s just that the process often strikes me as all so disjointed: saving a document in one app and then starting up a separate utility to transfer the file just screams at me for an overhaul.)
我真正想要的是能够简单地调用类似(What I really desired was to be able to simply call something like) GetFile()
(或运行一个独立的应用程序),可以选择不带任何参数,并显示所有必需的GUI,以便我可以在过去8到9年中习惯于从任何地方获取任何文件,即通过类似标准的东西((or run a standalone app), optionally with no parameters, and have it present all the necessary GUI required to allow me to get any file from anywhere and in the manner to which I’ve become accustomed over the last 8-9 years, namely via something like the standard)**打开/保存(Open/Save)**对话.(dialogs.)
这就是我在这里尝试做的.(And that is what I’ve tried to do here.)
**EasyFtp(EasyFtp)**是一个不费吹灰之力的实用程序(不尊重任何没有大脑的人),它只是包装了一堆可以完成所有工作的类.(is a no-brainer utility (no disrespect to anyone out there without a brain) which simply wraps a bunch of classes which do all the work.)
注意(Note):我将其包装为EXE的原因是允许它受到以下支持(: The reason I’ve wrapped it as an EXE is to allow it to be supported by) 待办事项清单(TodoList) 的"工具"界面.通过将类直接放到您自己的应用程序中,可以很容易地使用它,我将在后面解释.(’s ‘Tool’ interface. It can just as easily be used by dropping the classes directly into your own application as I will explain later.)
要求(Requirements)
我已经暗示了一些要求,但这是更详尽的清单:(I’ve already hinted at some of the requirements but here’s a more exhaustive list:)
- 直观易懂.(Visually straightforward and familiar.)
- 无需配置编辑.(No configuration editing.)
- 无缝.(Seamless.)
- 没有RC文件资源(尤其是要用于多个应用程序时).(No RC file resources (especially if it’s meant to be leveraged into multiple apps).)
- 完全免费(始终).(Totally free (always).)
- 轻量级(请注意,它是MFC-所有事物都是相对的).(Lightweight (mind you, it’s MFC - all things are relative).)
- 可配置-即我可以传递或多或少的信息,其余信息将由我索取.(Configurable - i.e. I can pass as much or as little information and the rest will be requested of me.)
设计(Design)
我设想的基本工作流程如下:(The basic workflows that I envisaged were these:)
-
上载档案(Uploading a file)
- 显示标准的"打开"对话框以引出要上传的本地文件.(Show standard ‘Open’ dialog to elicit the local file to be uploaded.)
- 显示"服务器详细信息"对话框,以检索服务器名称,用户名和密码.(Show ‘Server Details’ dialog to retrieve server name, username and password.)
- 登录到服务器并显示远程"另存为"对话框,以检索要上传到的远程文件路径.(Log on to server and display remote ‘Save As’ dialog to retrieve the remote file path to upload to.)
- 在上传过程中显示进度/取消对话框.(Display a progress/cancel dialog during the upload.) 注意(Note):这些数字直接对应于上面的图像编号.(: These numbers correspond directly to the image numbers above.)
-
下载文件(Downloading a file)
- 显示"服务器详细信息"对话框,以检索服务器名称,用户名和密码.(Show ‘Server Details’ dialog to retrieve server name, username and password.)
- 登录到服务器并显示远程"打开"对话框,以检索要下载的远程文件路径.(Log on to server and display remote ‘Open’ dialog to retrieve the remote file path to download.)
- 显示标准的"另存为"对话框以引出要保存到的本地文件.(Show standard ‘Save As’ dialog to elicit the local file to be saved to.)
- 在下载过程中显示进度/取消对话框(Display a progress/cancel dialog during the download)
听起来很简单,不是吗?(Sounds simple doesn’t it?)
它的优点在于它看起来很简单,同时考虑到(我一如既往),我已经编写了许多使它适用于其他项目的代码.(And the beauty of it was that it was just as simple as it appears, taking into account (as I always do) that I had already written a lot of the code necessary to make it work for other projects.)
而有问题的特定代码是(And the particular code in question is) CRuntimeDlg
我首先介绍的是(which I first presented in) 待办事项清单(ToDoList) 作为不使用RC编辑器以及不依赖RC对话框模板的结果而构造对话框的一种方法.(as a means of constructing dialog boxes without the use of the RC editor and the resultant dependency on RC based dialog templates.)
注意(Note):如果您不清楚为什么这是一个如此重要的问题,请考虑如果要重用依赖于对话框资源的代码,该怎么办:(: If you’re not clear on why this is such a significant issue, consider what has to happen if you want to reuse code that relies on dialog resources:)
- 复制/包括(Copy/Include the).H(.h*)*/(*/*)*.cpp(*.cpp*)*文件.(*files.*)
- 从中复制对话框资源(Copy the dialog resources from the).RC(.RC*)*文件.(*file.*)
- 验证没有讨厌(Verify that no nasty)资源.h(resource.h)Visual Studio尽其所能确保可以合并到新资源中而导致出现问题.(issues have arisen as a result of Visual Studio doing whatever it wants to ensure it can merge in the new resources.)
代替,(Instead,)
CRuntimeDlg
将允许您将对话框控件定义嵌入对话框的(will allow you embed dialog control definitions within the dialog’s).cpp(.cpp*)*文件,没有任何其他摆弄.(*file without any other fiddling about.*)
**任何控制(Any control)**Visual Studio的资源编辑器可以放置的内容(目前可能是ActiveX除外)也可以在((possibly except ActiveX, at present) that can be placed by Visual Studio’s resource editor can also be used in a) CRuntimeDlg
基于对话框.(based dialog.)
所有这些加在一起就使您能够不加思索地将文件移动到任何地方-每次都对我有用.(It all adds up to being able to move the files anywhere without a second thought - works for me every time.)
实作(Implementation)
这是一个相当简化的图,显示了主类关系(This is a rather simplified diagram which shows the principal class relationships)
{{DIAGRAM_START
: EasyFtp Class Diagram
.------------.
|CEasyFtpApp |
| |
|Application |
|class |
.v-----------·
|uses
|
.-v---------------.
|CRemoteFile |
| |
|Orchestrates the |
|GUI and does the |
|uploading and |
---< downloading >--------
| ·-v---------------· |
uses| |uses |uses
| | |
.--------------v v------------------. v--------------------.
|CServerDialog | |CRemoteFileDialog | |CProgressDlg |
| | | | | |
|Retrieves the | |Remote version of | |Shows dload/uload |
|server details| |CFileDialog | |progress and doubles|
| | | | | as a cancel dialog |
·-------------v· ·v-----------------· ·v-------------------·
| | |
derived| |derived |derived
from| |from |from
------>v-----------------<------
|CRuntimeDlg |
| |
|Implements dialogs|
| without resource |
|templates |
| |
·------------------·
}}DIAGRAM_END
(由以下人员提供)((drawn courtesy of) 代码绘图仪(CodePlotter) ©(©)抽象勺2003)(AbstractSpoon 2003))
其余代码由实用程序类组成,其中最有趣的是:(The rest of the code comprises of utility classes, the most interesting of which are:)
-
CDeferWndMove
包装周围(Wrapper around)::DeferWindowPos()
提供方便的附加内容,例如(offering handy additions like)OffsetCtrl()
和(and)ResizeCtrl()
.(.) -
CDlgUnits
包装周围(Wrapper around)::MapDialogRect()
提供重载进行转换(offering overloads to convert)short
s(s,)int
s(s,)long
,像素和对话框单位(DLSu)之间的s,POINT,SIZE和REACT.(s, POINTs, SIZEs and RECTs to and from pixels and dialog units (DLUs).) -
CSysImageList
Windows系统映像列表周围的包装器(可访问文件图标).(Wrapper around the Windows system image list (which provides access to file icons).) -
CFileEdit
CEdit
派生工具提供集成的浏览功能,并使用扩大的非客户端边框在其中绘制文件的图标.(derivative providing integrated browsing capabilities and using an enlarged non-client border in which to draw the file’s icon.)
使用EasyFtp(实用程序)(Using EasyFtp (the utility))
默认情况下,即命令行上没有任何内容,EasyFtp将默认为"下载"模式,并将遵循上述工作流程.(By default, i.e. with nothing on the command line, EasyFtp will default to ‘Download’ mode, and will follow the workflow outlined above.)
但是,可以使用以下命令行开关,以便您可以简化或修改这些默认设置((However, the following command line switches are available so that you can streamline or modify these defaults ()注意(note):必须在开关之前加上(: switches must be preceded by)–(-)要么(or)/(/)):():)
-
**向上(up)**指定您要上传文件,命令行上没有其他内容,这将在文章图像中显示工作流程.(Specifies you want to upload a file, with nothing else on the command line this will display the workflow in the article image.)
-
**rp(rp)**指定要上传或下载的远程路径.这可以是完整路径(减去服务器位),也可以只是一个文件夹,在这种情况下,它需要一个尾随的正斜杠.(Specifies the remote path to upload to, or download from. This can be a full path (less the server bit) or just a folder, in which case it needs a trailing forward slash.)
-
**lp(lp)**指定要从中上传或下载到的本地路径.这可以是完整路径或文件夹(不需要尾随反斜杠).(Specifies the local path to upload from, or download to. This can be a full path or a folder (no trailing backslash required).)
-
**g(ag)**指定要使用的代理字符串(如果EasyFtp由另一个应用程序生成则很有用).(Specifies the agent string to use (useful if EasyFtp is being spawned by another app).)
-
**sv(sv)**指定服务器位置,例如www.microsoft.com.(Specifies the server location e.g.. www.microsoft.com.)
-
**我们(us)**指定用户名,如果未指定,则将执行"匿名"登录.(Specifies the user name, if none is specified then an ‘anonymous’ login will be performed.)
-
**w(pw)**指定帐户的密码,如果用户名为空,则可以保留为空.(Specifies the password for the account, can be left blank if the username is blank.)
-
**一个(an)**指定匿名登录,传递空的用户名/密码字符串.(Specifies anonymous login, empty username/password strings are passed.)
-
**nl(nl)**指定_not_,以在上传时将文件名转换为小写.(*Specifies _not_ to convert filenames to lowercase when uploading.*)
-
**数控(nc)**指定对"确认覆盖"对话框的抑制,如果上载或下载目标路径已经存在.(Specifies suppression of the ‘confirm overwrite’ dialog which appears if the upload or download target path already exists.)
使用代码(Using the code)
如果您希望将代码直接集成到自己的应用程序中,那么这同样容易.(If you would rather integrate the code directly into your own application then it’s equally easy.)
- 从中取出所有文件(Take all the files from the)*共享(shared)*文件夹(在zip文件中)并将其复制到(folder (in the zip file) and copy them to a)**单一地点(single location)**任何你想的地点都可以.(anywhere you want.)
- 在要具有FTP支持的文件上,添加以下行(To the file you want to have FTP support, add the line)
#include <span class="code-string">"[path]\remotefile.h"</span>
- 最后,无论您要下载或上传文件的位置,请添加如下代码:(Finally, wherever you want to download or upload files, add the code like this:)
历史(History)
-
1.0(1.0)-25(- 25)日(th)2004年2月(Feb, 2004)
- 初始发行.(Initial release.)
-
1.0.1(1.0.1)-26(- 26)日(th)2004年2月(Feb, 2004)
- 修复了取消文件打开对话框后仍然弹出服务器对话框的错误(仅用于上传).(fixed bug where server dialog still pops up after canceling file open dialog (uploads only).)
- 修复了与未正确初始化文件名缓冲区传递给文件打开对话框有关的崩溃错误.(fixed crash bug relating to not properly initializing the filename buffer pass to the file open dialog.)
-
1.0.2(1.0.2)-26(- 26)日(th)2004年2月(Feb, 2004)
- 修复了在指定本地路径后"另存为"对话框仍然出现的错误.(fixed bug where Save As dialog was still appearing when the local path had been specified.)
- ‘(')nl(nl)‘开关已添加到(’ switch added to)*防止(prevent)*远程上载路径名将转换为小写.(remote upload pathnames being converted to lowercase.)
-
1.1(1.1)-10(- 10)日(th)2004年3月(Mar, 2004)
- 添加了对拖放到应用程序图标(在资源管理器中或在桌面上)的支持.(support added for drag’n’drop onto the application icon (in explorer or on the desktop).)**注意:(Note:)**这意味着,一旦您设置了应用程序命令行以指向您的FTP服务器,就可以从桌面拖放文件了.(this means that once you have setup the app command line to point to your FTP server you can do drag and drop uploading from your desktop.)
- 现在可以一次上传或下载多个文件.(multiple files can now be uploaded or downloaded at once.)
- 修复了各种与UI相关的错误.(various UI related bugs fixed.)
-
1.3(1.3)-23(- 23)rd(rd)2004年3月,(Mar, 2004 ()不确定1.2发生了什么(not sure what happened to 1.2))())
- 修复了许多错误.(many bugs fixed.)
- 添加了匿名登录. (可以使用(anonymous login added. (Can be initialized using the)**-一个(-an)**命令行开关.)(command line switch.))
- 如果存在目标上传或下载文件,则添加确认对话框. (可以使用(confirmation dialog added if target upload or download file(s) exist. (Can be suppressed using the)**-nc(-nc)**开关.)(switch.))
- 改进了错误报告功能,尽管我还没有翻译HTTP错误.(improved error reporting, although I’m not yet translating HTTP errors.)
-
**1.3.1(1.3.1)**25(25)日(th)2004年3月(Mar, 2004)
- uxtheme.h(uxtheme.h)/(/)时程(tmschema.h)添加到源代码(感谢(added to source code (thanks to)杰`卡(Jay.ca)).().)
-
**1.3.2(1.3.2)**27(27)日(th)2004年3月(Mar, 2004)
- schemadef.h(schemadef.h)添加到源代码(感谢(added to source code (thanks to)阿德南(Adnan)).().)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 C++ VC6 WinXP Win2003 Win2K MFC Visual-Studio Dev 新闻 翻译