找回密码
 加入
搜索
查看: 2639|回复: 2

[网络通信] [已解决]Windows 7 下 FTP功能有问题,请高手帮忙检查下代码!

[复制链接]
发表于 2010-9-27 08:55:01 | 显示全部楼层 |阅读模式
本帖最后由 maxkingmax 于 2010-10-26 21:01 编辑

做了个自动上传种子到家用BT机的小程序,在WIN XP 下测试正常,但是在Win7 下无法正常工作
具体表现在:
出现上传进度窗口后,停止响应!

不知道是不是 Win7下的 FTPex.au3  兼容性的问题

#include <FTPEx.au3>
#include <file.au3>
#include <Constants.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $Form1,$Progress1 ,$Progress2 ,$Label1 ,$Label2 ,$currentfile,$currentnum,$totalnum

Dim $path = "D:\btpeer"
Dim $address = "myftp.com",$tcpip,$notip

gettcpip()  ;测试是否是局域网
func gettcpip()
        TraySetToolTip("正在查找服务器位置...")
;~         $a = 0

                $ping1 = Ping("192.168.1.111")
                $ping2 = Ping("192.168.1.10")
                $ping3 = Ping($address)
;~                 ConsoleWrite($ping1&" "&$ping2&" "&$ping3)
                Select
                        Case $ping1 = 0 And $ping2 = 0 And $ping3 > 0
                                TCPStartup()
                                $tcpip = TCPNameToIP($address)
                                TCPShutdown()
                                TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
                        Case $ping1 > 0 And ($ping2 = 0 Or $ping2 > 0) And ($ping3 > 0 Or $ping3 = 0)
                                $address = "192.168.1.111"
                                $tcpip = $address
                                TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
                        Case ($ping1 > 0 Or $ping1 = 0) And $ping2 > 0 And ($ping3 > 0 Or $ping3 = 0)
                                $address = "192.168.1.10"
                                $tcpip = $address
                                TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
                        Case $ping1 = 0 And $ping2 = 0 And $ping3 = 0
                                $tcpip = ""
;~                                 If $a = 0 Then
                                        TrayTip("无法获取服务器位置", "可能是服务器未开,或网络连接不正常!", 2)
;~                                         $a = $a + 1
;~                                 EndIf
                                TraySetToolTip("无法获取服务器位置,可能是服务器未开,或网络连接不正常!")
                EndSelect

EndFunc   ;==>gettcpip


;;程序主体
While 1

If FileExists($path & "\*.torrent") Then
                                        $file = _FileListToArray($path, "*.torrent", 1)
                                        If IsArray($file) Then
                                                $session = _FTP_Open("myftp")
                                                $myftp = _FTP_Connect($session, $tcpip, "anonymous", "")
                                                If @error = -1 Then
                                                        If $notip = 1 Then

                                                                TrayTip("无法连接", "无法连接到远程 FTP Server,请检查网络连接或联系 FTP Server", 3)
                                                                $notip = 0
                                                        EndIf
                                                        Sleep(3000)
                                                        ContinueLoop
                                                EndIf
                                                $notip = 1

                                                gui()
                                                For $i = 1 To $file[0]  ;这段循环用于测试种子是否下载完毕,防止上传的种子因为未下载完全就上传,导致BT任务失败!
                                                        Do
                                                                $size = FileGetSize($path & "\" & $file[$i])
                                                                Sleep(500)
                                                                $size2 = FileGetSize($path & "\" & $file[$i])
                                                                Sleep(500)
                                                                $size3 = FileGetSize($path & "\" & $file[$i])
                                                                Sleep(500)
                                                                If $size3=0 And $size3=$size Then
                                                                        ExitLoop
                                                                EndIf
                                                        Until $size2 = $size And $size3 = $size And $size3 = $size2 And $size > 1024 * 5

;~                                                         TrayTip("正在传送" & $filelist[$i], "文件大小: " & Round($size3 / 1024,2) & " KB", 2)

                                                
                                                        $currentfile=$file[$i]
                                                        $currentnum=$i
                                                        $totalnum=$file[0]
                                                        

;~                                                         _FTP_fileput($myftp, $path & "\" & $filelist[$i], $filelist[$i])
                                                        _FTP_ProgressUpload($myftp, $path & "\" & $file[$i], $file[$i],'uppress')
;~                                                         TrayTip("进度: " & $i & "/" & $file[0], $file[$i] & "已经传送完毕!", 2)
;~                                                         GUICtrlSetData($Progress2, 100*($i/$file[0]))
;~                                                                 _TCP_Client_Send(String($size3))
                                                        Sleep(2100)
                                                Next
                                                        GUIDelete($form1)
                                                        _FTP_Close($session)
                                                        
;~                                                 For $i = 1 To $file[0]
;~                                                         FileDelete($path & "\" & $file[$i])
;~                                                 Next
                                                
                                        EndIf
                                EndIf
                                
                                
                                
WEnd                                
                                
                                
Func gui() ;创建上传进度窗口


$Form1 = GUICreate("", 330, 110, @DesktopWidth-330, @DesktopHeight-110-taskbarh(), BitOR($WS_MINIMIZEBOX,$WS_DLGFRAME,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Progress1 = GUICtrlCreateProgress(8, 24, 313, 25,$PBS_SMOOTH)
$Progress2 = GUICtrlCreateProgress(8, 74, 313, 25,$PBS_SMOOTH)
$Label1 = GUICtrlCreateLabel("当前文件:", 8, 4, 315, 17)
$Label2 = GUICtrlCreateLabel("总进度:", 8, 56, 311, 17)
GUISetState(@SW_SHOW)



EndFunc
func taskbarh() ;获取任务栏高度
$pos = WinGetPos("[class:Shell_TrayWnd]")
if isarray($pos) Then
        return $pos[3]
        else
                return 0
EndIf
EndFunc

Func uppress($Percentage) ;进度条控制
GUICtrlSetData($Progress1,$Percentage)
GUICtrlSetData($Progress2,1/$totalnum*$Percentage+($currentnum-1)/$totalnum*100)

GUICtrlSetData($Label2,"总进度: "&$currentnum&"/"&$totalnum&' ('&Int(1/$totalnum*$Percentage+($currentnum-1)/$totalnum*100)&'%)')
GUICtrlSetData($Label1,"当前文件: "&StringTrimLeft($currentfile, StringInStr($currentfile, "\", 0, -1))& ' ('&$Percentage&'%)')
Return 1
EndFunc

评分

参与人数 1金钱 +12 收起 理由
502762378 + 12

查看全部评分

发表于 2010-9-28 14:22:31 | 显示全部楼层
FTP的UDF是有些小问题的,我经常遇到FILECLOSE会卡掉的,LZ还是自己加MSGBOX看看在哪卡掉了。
 楼主| 发表于 2010-10-26 21:00:31 | 显示全部楼层
问题已经解决,在 Win7下的 FTP 连接必须指定为被动模式

$myftp = _FTP_Connect($session, $tcpip, "anonymous", "",1)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-21 00:21 , Processed in 0.088627 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表