找回密码
 加入
搜索
查看: 2071|回复: 3

[网络通信] 简单FTP上传(其它的看不懂了,麻烦老鸟翻译下)

[复制链接]
发表于 2011-4-29 15:26:34 | 显示全部楼层 |阅读模式
研究了大半天,没搞明白。
Simple FTP Uploader
#include <FTPEx.au3>
#include <File.au3>
#include <Misc.au3>
#Include <String.au3>
#NoTrayIcon

If _Singleton("FTuP",1) = 0 Then
    Msgbox(0,"FTuP Error:","FTuP is already running!")
    Exit
EndIf

Opt("TrayMenuMode",1)
$HelpItem = TrayCreateItem("Help")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TraySetState()

$FileDrive = ""
$FileDir = ""
$FileName = ""
$FileExt = ""

HotKeySet("^y","Upload")

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $HelpItem
    Msgbox(0,"FTuP - CQE:","Press Ctrl+Y to upload the file of which the path is on the clipboard." &@CRLF& "After the beep, you can use Ctrl+V to paste the link." &@CRLF&@CRLF& _
                    "CONFIGURATION:" &@CRLF&@CRLF& _
                    "FTP details are in FTP.conf or encrypted in FTPsecure.conf, sorted by line:" &@CRLF& "1 = FTP Server" &@CRLF& "2 = FTP Account" &@CRLF& "3 = FTP Password" &@CRLF& _
                    "4 = Directory to put the file in, include first and last slash!" &@CRLF& "5 = URL to the folder where the file is placed, include last slash!" &@CRLF&@CRLF& _
                    "If you have both FTP.conf and FTPsecure.conf, then FTPsecure.conf will be used." &@CRLF&@CRLF& _
                    "Also, the file FTuP.size needs to be on the server in the directory where the files are uploaded (see 4 in the list above)." & _
                    " FTuP.size should contain the file size limit in megabytes (MB)." &@CRLF&@CRLF&@CRLF& _
                    "OPTIONAL:" &@CRLF&@CRLF& _
                    "FTuP Encrypt can turn your regular FTP.conf into an encrypted version." &@CRLF& _
                    "To enable right click file uploads, run FTuP RightClick.")
    Case $msg = $ExitItem
    ExitLoop
    EndSelect
WEnd

Func Upload()
    $FilePath = ClipGet()
    If FileExists($FilePath) = 0 Then
        MsgBox(0,"FTuP Error:","The file you want to upload couldn't be found. No FTP connection was made.")
    Else
        If FileExists(@ScriptDir & "\FTPsecure.conf") = 0 Then
            If FileExists(@ScriptDir & "\FTP.conf") = 0 Then
                MsgBox(0,"FTuP Error:","No config file could be found.")
                $NoConfigs = 1
            Else
                $FTPSecure = 0
                $FTPServer = FileReadLine(@ScriptDir & "\FTP.conf",1)
                $FTPAccount = FileReadLine(@ScriptDir & "\FTP.conf",2)
                $FTPPassword = FileReadLine(@ScriptDir & "\FTP.conf",3)
                $FTPDir = FileReadLine(@ScriptDir & "\FTP.conf",4)
                $SiteClip = FileReadLine(@ScriptDir & "\FTP.conf",5)
                $NoConfigs = 0
            EndIf
        Else
            $FTPSecure = 1
            $FTPServer = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",1),"F3T8u8P7")
            $FTPAccount = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",2),"F3T8u8P7")
            $FTPPassword = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",3),"F3T8u8P7")
            $FTPDir = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",4),"F3T8u8P7")
            $SiteClip = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",5),"F3T8u8P7")
            $NoConfigs = 0
        EndIf

        If $NoConfigs = 0 Then
            $FtpOpen = _FTP_Open("ImageFTP")
            $FtpConnect = _FTP_Connect($FtpOpen,$FTPServer,$FTPAccount,$FTPPassword)
            If $FtpConnect = 0 Then
                If $FTPSecure = 0 Then
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& $FTPAccount & " + " & $FTPPassword & " on " & $FTPServer)
                Else
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& "Using encrypted FTP details.")
                EndIf
                _FTP_Close($FtpOpen)
            Else
                $FtpFileOpen = _FTP_FileOpen($FtpConnect,$FTPDir & "FTuP.size")
                If $FtpFileOpen = 0 Then
                    MsgBox(0,"FTuP Error:","FTuP.size couldn't be found, it should be on the server in the directory where the files are uploaded" & _
                    " (4th line of the configuration file). It should contain the file size limit in megabytes (MB).")
                    _FTP_Close($FtpOpen)
                Else
                    $FileSize = Round((FileGetSize($FilePath)/1048576),2)
                    $MaxSize = Number(BinaryToString(_FTP_FileRead($FtpFileOpen, 100)))
                    _FTP_FileClose($FtpFileOpen)
                    If $FileSize > $MaxSize Then
                        MsgBox(0,"FTuP Error:","Sorry, that file (" & $FileSize & " MB) exceeds the file size limit (" & $MaxSize & " MB) and will not be uploaded.")
                        _FTP_Close($FtpOpen)
                    Else
                        $PathSplit= _PathSplit($FilePath, $FileDrive, $FileDir, $FileName, $FileExt)
                        $File = Random(0,99,1) & $Filename & $FileExt
                        $FilePut = _FTP_FilePut($FtpConnect, $FilePath, $FTPDir & $File)
                        If $FilePut = 0 Then
                            MsgBox(0,"FTuP Error:", "Couldn't put the file on the server, despite a succesful connection.")
                            _FTP_Close($FtpOpen)
                        Else
                            _FTP_Close($FtpOpen)
                            ClipPut($SiteClip & $File)
                            Beep(500,100)
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc
发表于 2011-4-30 19:35:49 | 显示全部楼层
代码整理 一下
#include <FTPEx.au3>
#include <File.au3>
#include <Misc.au3>
#Include <String.au3>
#NoTrayIcon

If _Singleton("FTuP",1) = 0 Then
    Msgbox(0,"FTuP Error:","FTuP is already running!")
    Exit
EndIf

Opt("TrayMenuMode",1)
$HelpItem = TrayCreateItem("Help")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TraySetState()

$FileDrive = ""
$FileDir = ""
$FileName = ""
$FileExt = ""

HotKeySet("^y","Upload")

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $HelpItem
    Msgbox(0,"FTuP - CQE:","Press Ctrl+Y to upload the file of which the path is on the clipboard." &@CRLF& "After the beep, you can use Ctrl+V to paste the link." &@CRLF&@CRLF& _
                    "CONFIGURATION:" &@CRLF&@CRLF& _
                    "FTP details are in FTP.conf or encrypted in FTPsecure.conf, sorted by line:" &@CRLF& "1 = FTP Server" &@CRLF& "2 = FTP Account" &@CRLF& "3 = FTP Password" &@CRLF& _
                    "4 = Directory to put the file in, include first and last slash!" &@CRLF& "5 = URL to the folder where the file is placed, include last slash!" &@CRLF&@CRLF& _
                    "If you have both FTP.conf and FTPsecure.conf, then FTPsecure.conf will be used." &@CRLF&@CRLF& _
                    "Also, the file FTuP.size needs to be on the server in the directory where the files are uploaded (see 4 in the list above)." & _
                    " FTuP.size should contain the file size limit in megabytes (MB)." &@CRLF&@CRLF&@CRLF& _
                    "OPTIONAL:" &@CRLF&@CRLF& _
                    "FTuP Encrypt can turn your regular FTP.conf into an encrypted version." &@CRLF& _
                    "To enable right click file uploads, run FTuP RightClick.")
    Case $msg = $ExitItem
    ExitLoop
    EndSelect
WEnd

Func Upload()
    $FilePath = ClipGet()
    If FileExists($FilePath) = 0 Then
        MsgBox(0,"FTuP Error:","The file you want to upload couldn't be found. No FTP connection was made.")
    Else
        If FileExists(@ScriptDir & "\FTPsecure.conf") = 0 Then
            If FileExists(@ScriptDir & "\FTP.conf") = 0 Then
                MsgBox(0,"FTuP Error:","No config file could be found.")
                $NoConfigs = 1
            Else
                $FTPSecure = 0
                $FTPServer = FileReadLine(@ScriptDir & "\FTP.conf",1)
                $FTPAccount = FileReadLine(@ScriptDir & "\FTP.conf",2)
                $FTPPassword = FileReadLine(@ScriptDir & "\FTP.conf",3)
                $FTPDir = FileReadLine(@ScriptDir & "\FTP.conf",4)
                $SiteClip = FileReadLine(@ScriptDir & "\FTP.conf",5)
                $NoConfigs = 0
            EndIf
        Else
            $FTPSecure = 1
            $FTPServer = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",1),"F3T8u8P7")
            $FTPAccount = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",2),"F3T8u8P7")
            $FTPPassword = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",3),"F3T8u8P7")
            $FTPDir = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",4),"F3T8u8P7")
            $SiteClip = _StringEncrypt(0,FileReadLine(@ScriptDir & "\FTPsecure.conf",5),"F3T8u8P7")
            $NoConfigs = 0
        EndIf

        If $NoConfigs = 0 Then
            $FtpOpen = _FTP_Open("ImageFTP")
            $FtpConnect = _FTP_Connect($FtpOpen,$FTPServer,$FTPAccount,$FTPPassword)
            If $FtpConnect = 0 Then
                If $FTPSecure = 0 Then
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& $FTPAccount & " + " & $FTPPassword & " on " & $FTPServer)
                Else
                    MsgBox(0,"FTuP Error:","Couldn't connect to the FTP server." &@CRLF& "Using encrypted FTP details.")
                EndIf
                _FTP_Close($FtpOpen)
            Else
                $FtpFileOpen = _FTP_FileOpen($FtpConnect,$FTPDir & "FTuP.size")
                If $FtpFileOpen = 0 Then
                    MsgBox(0,"FTuP Error:","FTuP.size couldn't be found, it should be on the server in the directory where the files are uploaded" & _
                    " (4th line of the configuration file). It should contain the file size limit in megabytes (MB).")
                    _FTP_Close($FtpOpen)
                Else
                    $FileSize = Round((FileGetSize($FilePath)/1048576),2)
                    $MaxSize = Number(BinaryToString(_FTP_FileRead($FtpFileOpen, 100)))
                    _FTP_FileClose($FtpFileOpen)
                    If $FileSize > $MaxSize Then
                        MsgBox(0,"FTuP Error:","Sorry, that file (" & $FileSize & " MB) exceeds the file size limit (" & $MaxSize & " MB) and will not be uploaded.")
                        _FTP_Close($FtpOpen)
                    Else
                        $PathSplit= _PathSplit($FilePath, $FileDrive, $FileDir, $FileName, $FileExt)
                        $File = Random(0,99,1) & $Filename & $FileExt
                        $FilePut = _FTP_FilePut($FtpConnect, $FilePath, $FTPDir & $File)
                        If $FilePut = 0 Then
                            MsgBox(0,"FTuP Error:", "Couldn't put the file on the server, despite a succesful connection.")
                            _FTP_Close($FtpOpen)
                        Else
                            _FTP_Close($FtpOpen)
                            ClipPut($SiteClip & $File)
                            Beep(500,100)
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc
发表于 2011-5-1 01:26:54 | 显示全部楼层
不可能一行一行的或者一个单词和一个字母的解释吧?
你至少要指出那部分看不懂。
发表于 2011-5-1 01:27:46 | 显示全部楼层
代码这玩意,有时候很难解释,需要你自己的悟性。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 02:53 , Processed in 0.077283 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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