RAW FTP Commands Collection

Standard

可以用来自己写FTP Client。测试命名的方法:以window 自带的FTP命令为例:

命令行行下执行FTP,连接入FTP server。

然后通过Quote来执行RAW命令

 

C:UsersNolanShang>ftp 127.0.0.1
Connected to 127.0.0.1.
220-FileZilla Server version 0.9.37 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
User (127.0.0.1:(none)): nolan
331 Password required for nolan
Password:
230 Logged on
ftp> quote feat
211-Features:
MDTM
REST STREAM
SIZE
MLST type*;size*;modify*;
MLSD
UTF8
CLNT
MFMT
211 End
ftp>

Common Commands

  • ABOR – abort a file transfer
  • CWD – change working directory
  • DELE – delete a remote file
  • LIST – list remote files
  • MDTM – return the modification time of a file
  • MKD – make a remote directory
  • NLST – name list of remote directory
  • PASS – send password
  • PASV – enter passive mode
  • PORT – open a data port
  • PWD – print working directory
  • QUIT – terminate the connection
  • RETR – retrieve a remote file
  • RMD – remove a remote directory
  • RNFR – rename from
  • RNTO – rename to
  • SITE – site-specific commands
  • SIZE – return the size of a file
  • STOR – store a file on the remote host
  • TYPE – set transfer type
  • USER – send username

Uncommon Commands

  • ACCT* – send account information
  • APPE – append to a remote file
  • CDUP – CWD to the parent of the current directory
  • HELP – return help on using the server
  • MODE – set transfer mode
  • NOOP – do nothing
  • REIN* – reinitialize the connection
  • STAT – return server status
  • STOU – store a file uniquely
  • STRU – set file transfer structure
  • SYST – return system type

Descriptions

ABOR
Syntax: ABOR
Aborts a file transfer currently in progress.

ACCT*
Syntax: ACCT account-info
This command is used to send account information on systems that require it. Typically sent after a PASS command.

ALLO
Syntax: ALLO size [R max-record-size]
Allocates sufficient storage space to receive a file. If the maximum size of a record also needs to be known, that is sent as a second numeric parameter following a space, the capital letter “R”, and another space.

APPE
Syntax: APPE remote-filename
Append data to the end of a file on the remote host. If the file does not already exist, it is created. This command must be preceded by a PORT or PASV command so that the server knows where to receive data from.

CDUP
Syntax: CDUP
Makes the parent of the current directory be the current directory.

CWD
Syntax: CWD remote-directory
Makes the given directory be the current directory on the remote host.

DELE
Syntax: DELE remote-filename
Deletes the given file on the remote host.

HELP
Syntax: HELP [command]
If a command is given, returns help on that command; otherwise, returns general help for the FTP server (usually a list of supported commands).

LIST
Syntax: LIST [remote-filespec]
If remote-filespec refers to a file, sends information about that file. If remote-filespec refers to a directory, sends information about each file in that directory. remote-filespec defaults to the current directory. This command must be preceded by a PORT or PASVcommand.

MDTM
Syntax: MDTM remote-filename
Returns the last-modified time of the given file on the remote host in the format “YYYYMMDDhhmmss”: YYYY is the four-digit year, MM is the month from 01 to 12, DD is the day of the month from 01 to 31, hh is the hour from 00 to 23, mm is the minute from 00 to 59, and ss is the second from 00 to 59.

MKD
Syntax: MKD remote-directory
Creates the named directory on the remote host.

MODE
Syntax: MODE mode-character

Sets the transfer mode to one of:

  • S – Stream
  • B – Block
  • C – Compressed

The default mode is Stream.

NLST
Syntax: NLST [remote-directory]
Returns a list of filenames in the given directory (defaulting to the current directory), with no other information. Must be preceded by a PORT or PASV command.

NOOP
Syntax: NOOP
Does nothing except return a response.

PASS
Syntax: PASS password
After sending the USER command, send this command to complete the login process. (Note, however, that an ACCT command may have to be used on some systems.)

PASV
Syntax: PASV
Tells the server to enter “passive mode”. In passive mode, the server will wait for the client to establish a connection with it rather than attempting to connect to a client-specified port. The server will respond with the address of the port it is listening on, with a message like:
227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.

PORT
Syntax: PORT a1,a2,a3,a4,p1,p2
Specifies the host and port to which the server should connect for the next file transfer. This is interpreted as IP address a1.a2.a3.a4, port p1*256+p2.

PWD
Syntax: PWD
Returns the name of the current directory on the remote host.

QUIT
Syntax: QUIT
Terminates the command connection.

REIN*
Syntax: REIN
Reinitializes the command connection – cancels the current user/password/account information. Should be followed by a USER command for another login.

REST
Syntax: REST position
Sets the point at which a file transfer should start; useful for resuming interrupted transfers. For nonstructured files, this is simply a decimal number. This command must immediately precede a data transfer command (RETR or STOR only); i.e. it must come after any PORT or PASV command.

RETR
Syntax: RETR remote-filename
Begins transmission of a file from the remote host. Must be preceded by either a PORT command or a PASV command to indicate where the server should send data.

RMD
Syntax: RMD remote-directory
Deletes the named directory on the remote host.

RNFR
Syntax: RNFR from-filename
Used when renaming a file. Use this command to specify the file to be renamed; follow it with an RNTO command to specify the new name for the file.

RNTO
Syntax: RNTO to-filename
Used when renaming a file. After sending an RNFR command to specify the file to rename, send this command to specify the new name for the file.

SITE*
Syntax: SITE site-specific-command
Executes a site-specific command.

SIZE
Syntax: SIZE remote-filename
Returns the size of the remote file as a decimal number.

STAT
Syntax: STAT [remote-filespec]
If invoked without parameters, returns general status information about the FTP server process. If a parameter is given, acts like the LIST command, except that data is sent over the control connection (no PORT or PASV command is required).

STOR
Syntax: STOR remote-filename
Begins transmission of a file to the remote site. Must be preceded by either a PORT command or a PASV command so the server knows where to accept data from.

STOU
Syntax: STOU
Begins transmission of a file to the remote site; the remote filename will be unique in the current directory. The response from the server will include the filename.

STRU
Syntax: STRU structure-character

Sets the file structure for transfer to one of:

  • F – File (no structure)
  • R – Record structure
  • P – Page structure

The default structure is File.

SYST
Syntax: SYST
Returns a word identifying the system, the word “Type:”, and the default transfer type (as would be set by the TYPE command). For example: UNIX Type: L8

TYPE
Syntax: TYPE type-character [second-type-character]

Sets the type of file to be transferred. type-character can be any of:

  • A – ASCII text
  • E – EBCDIC text
  • I – image (binary data)
  • L – local format

For A and E, the second-type-character specifies how the text should be interpreted. It can be:

  • N – Non-print (not destined for printing). This is the default if second-type-character is omitted.
  • T – Telnet format control (<CR>, <FF>, etc.)
  • C – ASA Carriage Control

For L, the second-type-character specifies the number of bits per byte on the local system, and may not be omitted.

USER
Syntax: USER username
Send this command to begin the login process. username should be a valid username on the system, or “anonymous” to initiate an anonymous login.

C# Call by Name

Standard

sing .NET reflection we can attempt to access properties and function solely with their name.

 

The System.Reflection namespace holds a variety of classes and functions that takes C# programming to another level.

we accessed the Location property of myObject. We can also do the same through reflection:

Type t = myObject.GetType();
PropertyInfo p = t.GetProperty("Location");
Point location = (Point)p.GetValue(myObject, null);

Of course, PropertyInfo is location under the System.Reflection namespace. Notice that the code becomes significantly more complicated and susceptible to mistakes. For example, in the first example, trying to access a property that does not exist would trigger a compiler error. On the other hand, the example with Reflection compiles just fine no matter what property we try to access. The error will come up during run-time.

 

et’s take showMessage from our example above. The function does not return a value and does not take parameters. To call it with .NET reflection it would be done something like so:

Type t = this.GetType();
MethodInfo method = t.GetMethod("showMessage");
method.Invoke(this, null);

A word of warning. If you get a null-object exception that means the method was not found. The method has to be public for it to be able to be invoked through reflection. Also obfuscating the C# application can potentially cause the name of the method to change, which will cause the code to fail. These are just things to keep in mind.

Now let’s try to invoke the multiply function from the example above, which takes parameters and returns a value. The code is not all that different:

Type t = this.GetType();
MethodInfo method = t.GetMethod("multiply");
int result = (int)method.Invoke(this, new object[] { 3, 4 });

 

 

C# Set DataGridView Selection

Standard

DataGridView

When data is added or searched in a DataGridView, it make it easier for the user to programmatically change the DataGridView selection.

Unfortunately, setting the selected item is not as easy as a ListBox for example. The reasons being that DataGridView’s usually handle larger amounts of data and they are often bound to data sources. Either way, it’s a 3 step process.

Set DataGridView Selection

Here’s how to set the active row of a DataGridView. The two example variables will be dataGrid, which is a DataGridView, andindex, which is the index of the row you want to select with C# code.

First is to scroll down the DataGridView so the row is visible in the screen:

dataGridView1.FirstDisplayedScrollingRowIndex = index;
dataGridView1.Refresh();

Then you must select the row so that binding sources update their Current item:

dataGridView1.CurrentCell = dataGrid.Rows[index].Cells[0];

Finally, you can visually select the row with C#:

dataGridView1.Rows[index].Selected = true;

Conclusion

The C# code above assumes that you are trying to select an entire DataGridView row. However it is simple to adjust if you just want to select a Cell. Otherwise the code will work to set the DataGridView selection.

 

Optimizing C# Application

Standard

Code optimization is an important aspect of writing an efficient C# application. The following tips will help you increase the speed and efficiency of your C# code and applications.

1. Knowing when to use StringBuilder

You must have heard before that a StringBuilder object is much faster at appending strings together than normal string types.

The thing is StringBuilder is faster mostly with big strings. This means if you have a loop that will add to a single string for many iterations then a StringBuilder class is definitely much faster than a string type.

However if you just want to append something to a string a single time then a StringBuilder class is overkill. A simple stringtype variable in this case improves on resources use and readability of the C# source code.

Simply choosing correctly between StringBuilder objects and string types you can optimize your code.

2. Comparing Non-Case-Sensitive Strings

In an application sometimes it is necessary to compare two string variables, ignoring the cases. The tempting and traditionally approach is to convert both strings to all lower case or all upper case and then compare them, like such:

str1.ToLower() == str2.ToLower()

However repetitively calling the function ToLower() is a bottleneck in performace. By instead using the built-in string.Compare()function you can increase the speed of your applications.

To check if two strings are equal ignoring case would look like this:

string.Compare(str1, str2, true) == 0 //Ignoring cases

The C# string.Compare function returns an integer that is equal to 0 when the two strings are equal.

3. Use string.Empty

This is not so much a performance improvement as it is a readability improvement, but it still counts as code optimization. Try to replace lines like:

if (str == "")

with:

if (str == string.Empty)

This is simply better programming practice and has no negative impact on performance.

Note, there is a popular practice that checking a string’s length to be 0 is faster than comparing it to an empty string. While that might have been true once it is no longer a significant performance improvement. Instead stick with string.Empty.

4. Replace ArrayList with List<>

ArrayList are useful when storing multiple types of objects within the same list. However if you are keeping the same type of variables in one ArrayList, you can gain a performance boost by using List<> objects instead.

Take the following ArrayList:

ArrayList intList = new ArrayList();
intList.add(10);
return (int)intList[0] + 20;

Notice it only contains intergers. Using the List<> class is a lot better. To convert it to a typed List, only the variable types need to be changed:

List<int> intList = new List<int>();
intList.add(10)
return intList[0] + 20;

There is no need to cast types with List<>. The performance increase can be especially significant with primitive data types like integers.

5. Use && and || operators

When building if statements, simply make sure to use the double-and notation (&&) and/or the double-or notation (||), (in Visual Basic they are AndAlso and OrElse).

If statements that use & and | must check every part of the statement and then apply the “and” or “or”. On the other hand, && and ||go thourgh the statements one at a time and stop as soon as the condition has either been met or not met.

Executing less code is always a performace benefit but it also can avoid run-time errors, consider the following C# code:

if (object1 != null && object1.runMethod())

If object1 is null, with the && operator, object1.runMethod()will not execute. If the && operator is replaced with &,object1.runMethod() will run even if object1 is already known to be null, causing an exception.

6. Smart Try-Catch

Try-Catch statements are meant to catch exceptions that are beyond the programmers control, such as connecting to the web or a device for example. Using a try statement to keep code “simple” instead of using if statements to avoid error-prone calls makes code incredibly slower. Restructure your source code to require less try statements.

7. Replace Divisions

C# is relatively slow when it comes to division operations. One alternative is to replace divisions with a multiplication-shift operation to further optimize C#. The article explains in detail how to make the conversion.

Conclusion

As you can see these are very simple C# code optimizations and yet they can have a powerful impact on the performance of your application. To test out the optimizations, try out the free Optimizing Utility.

Profiling

An important concept when it comes to increasing the speed and efficiency of you C# code, is code profiling. A good profiler can not only let you know about the speed bottlenecks in your applications, but it can also help you with memory management. The best .Net profiler is probably RedGates ANTS Profiler. They have a free trial at their homepage you can download before purchasing the full product.

 

A tip about ADO.NET

Standard

通过ADO.NET取得的DataTable,Dataset中DataColumn的MaxLength属性有时取不到想要的值,比如有个varchar类型的字段,长度应该是100,但是返回的确是-1。

当然可以通过其他方式取得表的Schame信息,但这样多了一步。

通过查资料发现这是微软的一个BUG。解决办法很简单,设置一下SqlDataAdapter的MissingSchemaAction属性:

string strQuery = "SELECT * FROM tbl_MyTable";
objConn = new SqlConnection(strConnString);
objConn.Open();
objCmd = new SqlCommand(strQuery, objConn);
objDA = new SqlDataAdapter(objCmd);
objDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
objDS = new DataSet();
int iCount = objDA.Fill(objDS);

对句

Standard

史艷文與女神龍的對口詩
史:日月也有東西照,
苦:人生何處不相逢,
史:山川也有阡陌交,
苦:有緣千里來相會。

一頁書與海殤君所吟之詞
一: 甚矣吾衰矣,帳平生,交游零落,只今餘幾,白髮空垂三千丈,一笑人間千萬事,問何物能令公喜, 我見青山多嫵媚,料青山見我應如是,情與貌,略相似。
海: 一尊搔首東窗裡,想淵明停雲詩就,此時風味,江左沉酣求名著,豈識濁醪妙理,回首叫,雲飛風起,不恨古人吾不見,恨古人不見吾狂耳,知我者,二三子。

閒閒吟的詩 風塵千萬事,觀覽一笑之。
梅郎浦追昔
少年無端愛令名,也無學術誤蒼生.
白雲一笑懶如此,一遇天風吹便行.
石淨林恬氣藹然,山中不是管窺天.
心隨夕照沿崖去,坐聽淨淙瀑下泉.

鷲靈寺聖僧
閒來唸唸詩
誰知三隱寂寥中 因話尋盟別鷲峰 相送當門有修竹 為君葉葉起清風

出場詩
提水灌頂明鏡台,掃卻塵埃面目開,採瓜棚下無聖人,顛倒夢想從頭來。

寒山一花香

招牌詩
峭寒催換木綿裘,倚仗郊原作逝遊.最是秋風管閒事,紅他楓葉白人頭.

過的詩
(1) 浮生著甚苦奔忙,盛席華筵終散場.悲喜千般同幻夢,古今一夢盡荒唐.
(2) 中夜清寒入蘊袍,一杯香茗當香醪.鳥飛竹聲霜初下,人立梅花月正高.  無欲自然心似水,有營何止是如毛.春來擬約蕭蘭伴,重上天台看海濤.

寒雨夢中人

招牌詩
思君終夜把燈明,望斷紫陌慘生塵.絕情莫過絕音訊,縱沾雨露不是恩.

閒來唸唸的詩
愁境時侵總不愁,何妨物外任遨遊.世途成敗殘棋子,人事高低急水舟.
氣寒西北何人劍,聲滿東南幾處蕭.斗大明星爛無數,長天一月墜林梢.

素與夢在不夜天吟誦的詩
夢:「京城一見傾心,當時拜倒裙下,縱橫丹青意。」
素:「夢土十年相思,今日魂歸天上,褒貶方寸知。」
夢:「萬骨枯時人莫悟,忠魂義魄亦迷途,捫心應在三天外,噩噩渾渾盡匹夫。」
素:「身在家時心出家,是非否極未偏差,人生可貴為能悟,一樹花同一片霞。」

夢中人不夜天與素還真所吟之詩

添身偷取文狂號,清濁無成鬢蕭蕭,自省黯然功名誤,對眾強顏比楚騷,
絃歌唱滿古人恨,詩酒描寫江山嬌,柳霧蘆煙容易過,夢中沉浮世滔滔。

對星野殘紅所吟之詩
雲來山更佳,雲去山如畫,山因雲晦明,雲共高山下,風來雲起,伊人正在殘風斜陽裡。

夢中人與朱雀雲丹之詩詞對話

夢:假畫一堂,龍不吟,虎不嘯,花不聞香鳥不語,見美人可笑可笑。
朱:破書數卷,孔有曰,孟有云,學有杯淺庸有才,喝小子無知無知。
夢:古來忠良,遠離女色,姑娘豈有高才?
朱:青榜佳句,出自犬子,猜狗便是閣下!
夢:唯女子與小人,為難養也。
朱:是衣冠兼禽獸,豈好善乎?
夢:青龍白虎,朱雀豈知凌雲志,不配同儔。
朱:生前死後,夢中不知身為客,難成大器。
夢:京城一見傾心,當時拜倒裙下,縱橫丹青意。
朱:夢土十年相思,今日魂歸天上,褒貶方寸知。
夢:不夜天,不見天上人,夢中之人悼天人。
朱:光明世,無數世中仙,還真者仙真假仙。

閒閒念的詩
閒飲何事不從容,青衫袖底煎袍紅,擎杯莫道春芳淺,笑看星月掌握中。

Windows 7 No such interface supported 错误

Standard

今天Windows 自己系统更新,更新我重启系统,结果罢工,桌面上任何操作,如设置桌面,打开文件夹,打开控制面板等。都提示No such interface supported,无法进行操作。

用SFC没有效果,后来将系统的dll全部注册一下,就好了:

方法:

调出系统运行对话框:输入cmd,然后同时安装Ctrl+Shift,然后确认,则cmd以管理员身份运行:

接下来输入命令:

FOR /R C: %G IN (*.dll) DO "%systemroot%system32regsvr32.exe" /s "%G"

然后等待这个命令运行完毕,期间会弹出一些警告框,不用理他,因为有些DLL不是COM组件。

运行完重新启动系统,我的系统就正常了

VBScript-FTP上传和下载

Standard
Function FTPUpload(sSite, sUsername, sPassword, sLocalFile, sRemotePath)

  Const OpenAsDefault = -2
  Const FailIfNotExist = 0
  Const ForReading = 1
  Const ForWriting = 2

  Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
  Set oFTPScriptShell = CreateObject("WScript.Shell")

  sRemotePath = Trim(sRemotePath)
  sLocalFile = Trim(sLocalFile)

  '----------Path Checks---------
  'Here we willcheck the path, if it contains
  'spaces then we need to add quotes to ensure
  'it parses correctly.
  If InStr(sRemotePath, " ") > 0 Then
    If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
      sRemotePath = """" & sRemotePath & """"
    End If
  End If

  If InStr(sLocalFile, " ") > 0 Then
    If Left(sLocalFile, 1) <> """" And Right(sLocalFile, 1) <> """" Then
      sLocalFile = """" & sLocalFile & """"
    End If
  End If

  'Check to ensure that a remote path was
  'passed. If it's blank then pass a ""
  If Len(sRemotePath) = 0 Then
    'Please note that no premptive checking of the
    'remote path is done. If it does not exist for some
    'reason. Unexpected results may occur.
    sRemotePath = ""
  End If

  'Check the local path and file to ensure
  'that either the a file that exists was
  'passed or a wildcard was passed.
  If InStr(sLocalFile, "*") Then
    If InStr(sLocalFile, " ") Then
      FTPUpload = "Error: Wildcard uploads do not work if the path contains a " & _
      "space." & vbCRLF
      FTPUpload = FTPUpload & "This is a limitation of the Microsoft FTP client."
      Exit Function
    End If
  ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
    'nothing to upload
    FTPUpload = "Error: File Not Found."
    Exit Function
  End If
  '--------END Path Checks---------

  'build input file for ftp command
  sFTPScript = sFTPScript & "USER " & sUsername & vbCRLF
  sFTPScript = sFTPScript & sPassword & vbCRLF
  sFTPScript = sFTPScript & "cd " & sRemotePath & vbCRLF
  sFTPScript = sFTPScript & "binary" & vbCRLF
  sFTPScript = sFTPScript & "prompt n" & vbCRLF
  sFTPScript = sFTPScript & "put " & sLocalFile & vbCRLF
  sFTPScript = sFTPScript & "quit" & vbCRLF & "quit" & vbCRLF & "quit" & vbCRLF

  sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
  sFTPTempFile = sFTPTemp & "" & oFTPScriptFSO.GetTempName
  sFTPResults = sFTPTemp & "" & oFTPScriptFSO.GetTempName

  'Write the input file for the ftp command
  'to a temporary file.
  Set fFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
  fFTPScript.WriteLine(sFTPScript)
  fFTPScript.Close
  Set fFTPScript = Nothing  

  oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _
  " > " & sFTPResults, 0, TRUE

  Wscript.Sleep 1000

  'Check results of transfer.
  Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, _
  FailIfNotExist, OpenAsDefault)
  sResults = fFTPResults.ReadAll
  fFTPResults.Close

  oFTPScriptFSO.DeleteFile(sFTPTempFile)
  oFTPScriptFSO.DeleteFile (sFTPResults)

  If InStr(sResults, "226 Transfer complete.") > 0 Then
    FTPUpload = True
  ElseIf InStr(sResults, "File not found") > 0 Then
    FTPUpload = "Error: File Not Found"
  ElseIf InStr(sResults, "cannot log in.") > 0 Then
    FTPUpload = "Error: Login Failed."
  Else
    FTPUpload = "Error: Unknown."
  End If

  Set oFTPScriptFSO = Nothing
  Set oFTPScriptShell = Nothing
End Function

Function FTPDownload(sSite, sUsername, sPassword, sLocalPath, sRemotePath, _
         sRemoteFile)

  Const OpenAsDefault = -2
  Const FailIfNotExist = 0
  Const ForReading = 1
  Const ForWriting = 2

  Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
  Set oFTPScriptShell = CreateObject("WScript.Shell")

  sRemotePath = Trim(sRemotePath)
  sLocalPath = Trim(sLocalPath)

  '----------Path Checks---------
  'Here we will check the remote path, if it contains
  'spaces then we need to add quotes to ensure
  'it parses correctly.
  If InStr(sRemotePath, " ") > 0 Then
    If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
      sRemotePath = """" & sRemotePath & """"
    End If
  End If

  'Check to ensure that a remote path was
  'passed. If it's blank then pass a ""
  If Len(sRemotePath) = 0 Then
    'Please note that no premptive checking of the
    'remote path is done. If it does not exist for some
    'reason. Unexpected results may occur.
    sRemotePath = ""
  End If

  'If the local path was blank. Pass the current
  'working direcory.
  If Len(sLocalPath) = 0 Then
    sLocalpath = oFTPScriptShell.CurrentDirectory
  End If

  If Not oFTPScriptFSO.FolderExists(sLocalPath) Then
    'destination not found
    FTPDownload = "Error: Local Folder Not Found."
    Exit Function
  End If

  sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
  oFTPScriptShell.CurrentDirectory = sLocalPath
  '--------END Path Checks---------

  'build input file for ftp command
  sFTPScript = sFTPScript & "USER " & sUsername & vbCRLF
  sFTPScript = sFTPScript & sPassword & vbCRLF
  sFTPScript = sFTPScript & "cd " & sRemotePath & vbCRLF
  sFTPScript = sFTPScript & "binary" & vbCRLF
  sFTPScript = sFTPScript & "prompt n" & vbCRLF
  sFTPScript = sFTPScript & "mget " & sRemoteFile & vbCRLF
  sFTPScript = sFTPScript & "quit" & vbCRLF & "quit" & vbCRLF & "quit" & vbCRLF

  sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
  sFTPTempFile = sFTPTemp & "" & oFTPScriptFSO.GetTempName
  sFTPResults = sFTPTemp & "" & oFTPScriptFSO.GetTempName

  'Write the input file for the ftp command
  'to a temporary file.
  Set fFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
  fFTPScript.WriteLine(sFTPScript)
  fFTPScript.Close
  Set fFTPScript = Nothing  

  oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _
  " > " & sFTPResults, 0, TRUE

  Wscript.Sleep 1000

  'Check results of transfer.
  Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, _
                    FailIfNotExist, OpenAsDefault)
  sResults = fFTPResults.ReadAll
  fFTPResults.Close

  'oFTPScriptFSO.DeleteFile(sFTPTempFile)
  'oFTPScriptFSO.DeleteFile (sFTPResults)

  If InStr(sResults, "226 Transfer complete.") > 0 Then
    FTPDownload = True
  ElseIf InStr(sResults, "File not found") > 0 Then
    FTPDownload = "Error: File Not Found"
  ElseIf InStr(sResults, "cannot log in.") > 0 Then
    FTPDownload = "Error: Login Failed."
  Else
    FTPDownload = "Error: Unknown."
  End If

  Set oFTPScriptFSO = Nothing
  Set oFTPScriptShell = Nothing
End Function

VBScript-数组排序

Standard
Sub ArraySort(aArrayToSort, sOrder)
  'This Sub will sort the array passed as aArrayToSort
  For i = UBound(aArrayToSort) - 1 To 0 Step -1
    For j = 0 To i
      If aArrayToSort(j) < aArrayToSort(j+1) And sOrder = "desc" Then         sTempStr = aArrayToSort(j+1)         aArrayToSort(j+1) = aArrayToSort(j)         aArrayToSort(j) = sTempStr       ElseIf aArrayToSort(j) > aArrayToSort(j+1) And sOrder = "asc" Then
        sTempStr = aArrayToSort(j+1)
        aArrayToSort(j+1) = aArrayToSort(j)
        aArrayToSort(j) = sTempStr
      End If
    Next
  Next
End Sub

Sub DoubleArraySort(aArray1ToSort, aArray2ToSort, sOrder)
  'This Sub will sort the array passed as aArray1ToSort,
  'the values in aArray2ToSort, will not be sorted, but
  'will be reordered in the same relational order as
  'aArray1ToSort
  For i = UBound(aArray1ToSort) - 1 To 0 Step -1
    For j = 0 To i
      If aArray1ToSort(j) > aArray1ToSort(j+1) And sOrder = "desc" Then
        sTempStr = aArray1ToSort(j+1)
        aArray1ToSort(j+1) = aArray1ToSort(j)
        aArray1ToSort(j) = sTempStr

        sTempStr = aArray2ToSort(j+1)
        aArray2ToSort(j+1) = aArray2ToSort(j)
        aArray2ToSort(j) = sTempStr
      ElseIf aArray1ToSort(j) < aArray1ToSort(j+1) And sOrder = "asc" Then
        sTempStr = aArray1ToSort(j+1)
        aArray1ToSort(j+1) = aArray1ToSort(j)
        aArray1ToSort(j) = sTempStr

        sTempStr = aArray2ToSort(j+1)
        aArray2ToSort(j+1) = aArray2ToSort(j)
        aArray2ToSort(j) = sTempStr
      End If
    Next
  Next
End Sub