本文轉自 http://www.ajdblog.cn/post/600/ ,測試成功

把本文後面的MyFtp.au3 udf保存到include目錄。
文件名為什麼要是MyFtp.au3,而不是Ftp.au3
我們把所有自己寫的或經過自己修改的udf腳本文件名的前面加上My,這樣備份腳本文件時可以迅速定位到以My開頭文件名的腳本文件。

1 打造最好的ftp上傳軟件_autoit實例1-單文件上傳
[Copy to clipboard] [ - ]
CODE:
#include-once
#include <MyFtp.au3>

Local $s_ServerName, $s_Username, $s_Password,$s_LocalFile, $s_RemoteFile
;服務器,也可以是ip地址
$s_ServerName="http://www.ajdblog.cn"
;用戶名
$s_Username=http://www.ajdblog.cn
;密碼
$s_Password="http://www.ajdblog.cn"
;本地文件
$s_LocalFile="D:\test.html"
;遠程目錄
$s_RemoteDir="/public_html/"
;yidabu.com提示:遠程文件路徑。這裡用正則表達式匹配自動產生,如果文件很多時,這樣會很方便
$s_RemoteFile="/public_html/" & StringRegExpReplace($s_LocalFile,'^.+?\\([^\\]+)$','$1')
;$s_RemoteFile="/public_html/test.html"

Local $Re=ftpTest( $s_ServerName, $s_Username, $s_Password,$s_LocalFile, $s_RemoteFile)
If $Re Then
;在scite編輯器輸出區打印出函數執行結果
ConsoleWrite("sucessed" & @LF)
Else
ConsoleWrite("failed" & @LF)
EndIf

;yidabu.com推薦用一個函數的形式來測試autoit 代碼
Func ftpTest( $s_ServerName, $s_Username, $s_Password,$s_LocalFile, $s_RemoteFile)
$Open = _FTPOpen ('ftp')
If Not $Open Then Return False
$Conn = _FTPConnect ($Open, $s_ServerName, $s_Username, $s_Password)
If Not $Conn Then Return False
Local $Ftpp
$Ftpp = _FtpPutFile ($Conn, $s_LocalFile, $s_RemoteFile)
$Ftpc = _FTPClose ($Open)
Return $Ftpp
EndFunc
2 打造最好的ftp上傳軟件_autoit實例2-多文件智能上傳
[Copy to clipboard] [ - ]
CODE:
#include-once
#include <MyFtp.au3>

Local $s_ServerName="www.yidabu.com"
Local $s_Username="http://www.yidabu.com"
Local $s_Password="http://bbs.yidabu.com/forum-2-1.html"
;本地文件,用包含文件路徑的數組
Local $s_LocalFile[2]=["D:\test\test1.html","D:\test\test2.html"]
;遠程目錄
Local $s_RemoteFile="/public_html/test/"

Local $Re=ftpTest( $s_ServerName, $s_Username, $s_Password,$s_LocalFile, $s_RemoteFile)

;yidabu.com推薦用一個函數的形式來測試autoit 代碼
Func ftpTest( $s_ServerName, $s_Username, $s_Password,$s_LocalFile, $s_RemoteFile)
Local $Open = _FTPOpen ('ftp')
If Not $Open Then Return False
Local $Conn = _FTPConnect ($Open, $s_ServerName, $s_Username, $s_Password)
If Not $Conn Then Return False
;yidabu.com提示:myFtpPutFile是yidabu改寫的ftp上傳autoit函數
Local $Ftpp = myFtpPutFile ($Conn, $s_LocalFile, $s_RemoteFile)
$Ftpc = _FTPClose ($Open)

If Not IsArray($Ftpp) Or UBound($Ftpp)<2 Then Return False
For $i = 1 To $Ftpp[0] Step 1
;yidabu.com提示:在scite編輯器輸出區打印出成功上傳的文件
ConsoleWrite("uploaded:" & $Ftpp[$i] & @LF)
Next

Return $Ftpp
EndFunc
autoit udf:MyFtp.au3
把代碼保存到Include\MyFtp.au3

代碼下載

http://freakshare.net/files/l1x1ya89/MyFtp.au3.html

arrow
arrow
    全站熱搜

    Felix 發表在 痞客邦 留言(0) 人氣()