Sign in to follow this  
Followers 0
BananaFredSoft

FTP Questions

11 posts in this topic

#1 ·  Posted (edited)

I have three questions about FTP.au3.

1. I made a function to return the contents of the folder:

Func List ($dir2)
    $array = _ArrayCreate(0)
    $first = _FTPFindFirstFile($Connection, $dir2)
    Do
        $next = _FTPFindNextFile($first, "*.*", 3)
        $error = @error
        _ArrayAdd($array, $next[6])
        $array[0] += 1
    Until $error
    _FTPClose($first)
    Return $array
EndFuncoÝ÷ Ù»­ò.±è­¶§i×h­×¥z×~)^¶§ºÇ¢¶+]¡ë'ßÛkzÛ«©î¥Ö­yÛޮȨíçè׫jr&jG¢¶·­º¹Úê]j×½êìöZ§"Úò¶¬ÚÞ¶êç³F®¶­sbb33c·&VED2ÒgV÷C¶fÆRçGBgV÷C°¢b33c¶F"ÒgV÷C²ògV÷C°¢b33c¶æWvæÖRÒgV÷C¶fÆS"çGBgV÷C°¥ôeE&VæÖTfÆRb33c´6öææV7FöâÂb33c¶F"fײb33c·&VED2Âb33c¶F"fײb33c¶æWvæÖRoÝ÷ ئ²êÞ¶­¶WÆ+-±hZµ©v§
è
Ç£¶Ø^v'¥«a¡öW©ä²)Úvö§qáޭ謶¬r¸©¶ØZ´¦Âäx(ØZ¶¬jYh~Ø^±ëax,jëh×6#include <FTP.au3>
#include <FTP2.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>

#include <GuiListView.au3>

$conts = _ArrayCreate(0)
$dir = "/"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("FTP Sign-in", 310, 147, 193, 115)
$Combo1 = GUICtrlCreateCombo(IniRead(@ScriptDir & "\FTPClientData.data", "Main", "SavedServer", ""), 48, 16, 257, 25)
$Label1 = GUICtrlCreateLabel("Server:", 8, 16, 38, 17)
$Label2 = GUICtrlCreateLabel("Username:", 8, 48, 55, 17)
$Input1 = GUICtrlCreateInput(IniRead(@ScriptDir & "\FTPClientData.data", "Main", "SavedUserName", ""), 64, 48, 233, 21)
$Label3 = GUICtrlCreateLabel("Password:", 8, 80, 53, 17)
$Input2 = GUICtrlCreateInput(_StringEncrypt(0, IniRead(@ScriptDir & "\FTPClientData.data", "Main", "SavedPassword", ""), "12fHjkd73n"), 64, 80, 233, 21, $ES_PASSWORD)
$Button1 = GUICtrlCreateButton("Sign In", 8, 112, 291, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If BitAND(GUICtrlRead($Input1) <> IniRead(@ScriptDir & "\FTPClientData.data", "Main", "SavedUserName", ""), GUICtrlRead($Combo1) <> IniRead(@ScriptDir & "\FTPClientData.data", "Main", "SavedServer", "")) Then
                If MsgBox(4, "Save Username/Server?", "Should the username,and server automatically be entered from now on?") = 6 Then
                    IniWrite(@ScriptDir & "\FTPClientData.data", "Main", "SavedServer", GUICtrlRead($Combo1))
                    IniWrite(@ScriptDir & "\FTPClientData.data", "Main", "SavedUserName", GUICtrlRead($Input1))
                    If MsgBox(4, "Save password?", "Should the password be automatically entered from now on?") = 6 Then
                        IniWrite(@ScriptDir & "\FTPClientData.data", "Main", "SavedPassword", _StringEncrypt(1, GUICtrlRead($Input2), "12fHjkd73n"))
                    EndIf
                EndIf
            EndIf
            $handle = DLLOpen('wininet.dll')
            $Session = _FtpOpen("MyFTP Control")
            $Connection = _FTPConnect($Session, GUICtrlRead($Combo1), GUICtrlRead($Input1), GUICtrlRead($Input2), 21, 1, 0x8000000)
            If $Connection <> 0 Then
                $Server = GUICtrlRead($Combo1)
                $Password = GUICtrlRead($Input2)
                $UserName = GUICtrlRead($Input1)
                GUIDelete($Form1)
                ExitLoop
            Else
                MsgBox(0, "Connection Error", "There has been a connection error. The server, password, or account name may be incorrect.")
            EndIf
    EndSwitch
WEnd

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Colin\My Documents\ftp.kxf
$Form1 = GUICreate("FTP Client", 633, 449, 193, 115)
$CurrentAdress = GUICtrlCreateLabel($Server, 192, 8, 300)
$ListView1 = GUICtrlCreateListView("File Name", 8, 32, 513, 409)
_GUICtrlListView_SetColumnWidth($ListView1, 0, 500)
$Button3 = GUICtrlCreateButton("Delete", 528, 32, 99, 25, 0)
$Button4 = GUICtrlCreateButton("Rename", 528, 64, 99, 25, 0)
$Button5 = GUICtrlCreateButton("Download", 528, 96, 99, 25, 0)
$Button6 = GUICtrlCreateButton("Copy Path", 528, 128, 97, 25, 0)
$Button7 = GUICtrlCreateButton("Upload File", 528, 200, 97, 25)
$UploadDirectory = GUICtrlCreateButton("Upload Folder", 528, 232, 97, 25)
$CreateDirectory = GUICtrlCreateButton("Create Directory", 528, 264, 97, 25)
$FileSize = GUICtrlCreateLabel("", 528, 160, 34, 17)
GUISetState(@SW_SHOW)
$read = List("/")
For $i = 1 to $read[0]
    $a = GUICtrlCreateListViewItem($read[$i], $ListView1)
    _ArrayAdd($conts, $a)
    $conts[0] += 1
Next
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _FTPClose($Session)
            Exit
        Case $CreateDirectory
            $dirname = InputBox("Folder Name", "Please enter the name of the folder you want to create.")
            If not @error Then
                $return = _FTPMakeDir($Connection, $dirname)
                If $return Then
                    RedoList($dir)
                    MsgBox(0, "Folder Create", "The folder was successfully created.")
                Else
                    MsgBox(0, "Folder Create", "The folder creation failed.")
                EndIf
            EndIf
        Case $Button5
            $readC = GUICtrlRead($ListView1)
            If $readC <> 0 Then
                $readTC = StringTrimRight(GUICtrlRead($readC), 1)
                $save = FileSaveDialog("Download " & $readTC, "", "All Files (*.*)", -1, $readTC)
                $get = _FTPGetFile($Connection, "/" & $readTC, $save)
                If $get Then
                    MsgBox(0, "File Download", "The file was successfully downloaded.")
                    ShellExecute($save)
                Else
                    MsgBox(0, "File Download", "The file download failed.")
                EndIf
            EndIf
        Case $Button7
            $from = FileOpenDialog("Upload File", "", "All Files (*.*)")
            If FileExists($from) Then
                $upload = _FTPPutFile($Connection, $from, "/" & getname($from))
                If $upload Then
                    RedoList($dir)
                    MsgBox(0, "File Uploaded", "Your file has been successfully uploaded.")
                Else
                    MsgBox(0, "Upload Failed", "The file upload has failed.")
                EndIf
            EndIf
        Case $UploadDirectory
            $directory = FileSelectFolder("Choose a folder to upload.", "")
            If FileExists($directory) Then
                _FTPPutFolderContents($Connection, $directory, $dir, 1)
                RedoList($dir)
            EndIf
        Case $Button3
            $readC = GUICtrlRead($ListView1)
            If $readC <> 0 Then
                $readTC = StringTrimRight(GUICtrlRead($readC), 1)
                If MsgBox(4, "Confirm File Delete", "Are you sure you want to delete " & $readTC & "?") = 6 Then
                    $del = _FTPDelFile($Connection, "/" & $readTC)
                    If $del = 1 Then
                        RedoList($dir)
                        MsgBox(0, "Deletion Successful", "The file you selected has been deleted.")
                    Else
                        MsgBox(0, "Deletion Failed", "The file deletion failed.")
                    EndIf
                EndIf
            EndIf
        Case $Button4
            $readC = GUICtrlRead($ListView1)
            If $readC <> 0 Then
                $readTC = StringTrimRight(GUICtrlRead($readC), 1)
                $newname = InputBox("Rename File", "Please enter the new name for this file.", $readTC)
                If Not @error Then
                    $rename = _FTPRenameFile($Connection, "/" & $readTC, "/" & $newname)
                    If $rename Then
                        RedoList($dir)
                        MsgBox(0, "File Rename", "The file has been successfully renamed.")
                    Else
                        MsgBox(0, "File Rename", "The file rename failed.")
                    EndIf
                EndIf
            EndIf
        Case $ListView1
            $readread = StringTrimRight(GUICtrlRead(GUICtrlRead($ListView1)), 1)
            If $readread Then
                If StringInStr($readread, ".") = 0 Then
                    $dir = $dir & $readread
                    RedoList($dir)
                EndIf
            Else
                $dir = "/"
                RedoList($dir)
            EndIf
    EndSwitch
WEnd

Func List ($dir2)
    $array = _ArrayCreate(0)
    $first = _FTPFindFirstFile($Connection, $dir2)
    Do
        $next = _FTPFindNextFile($first, "*.*", 3)
        $error = @error
        _ArrayAdd($array, $next[6])
        $array[0] += 1
    Until $error
    _FTPClose($first)
    Return $array
EndFunc

Func getdir($filename)
    $split = StringSplit($filename, "\")
    If Not @error Then
        $dira = ""
        $num = 1
        Do
            $dira &= $split[$num] & "\"
            $num += 1
        Until $num = $split[0]
        Return $dira
    EndIf
EndFunc   ;==>getdir

Func getname($filename)
    Return StringReplace($filename, getdir($filename), "")
EndFunc

Func RedoList($dir3 = "/")
    GUICtrlSetData($CurrentAdress, $Server & $dir3) 
    _FTPSetCurrentDir($Connection, $dir3)
    For $i = 1 To $conts[0]
        GUICtrlDelete($conts[$i])
    Next
    $conts = _ArrayCreate(0)
    $read = List($dir3)
    For $i = 1 to $read[0]
        $a = GUICtrlCreateListViewItem($read[$i], $ListView1)
        _ArrayAdd($conts, $a)
        $conts[0] += 1
    Next
EndFunc

Func S ($read)
    $StringSplitArray = StringSplit($read, "|")
    Return $StringSplitArray[0]
EndFunc
Edited by BananaFredSoft

Share this post


Link to post
Share on other sites



I have three questions about FTP.au3.

1. I made a function to return the contents of the folder:

Func List ($dir2)
    $array = _ArrayCreate(0)
    $first = _FTPFindFirstFile($Connection, $dir2)
    Do
        $next = _FTPFindNextFile($first, "*.*", 3)
        $error = @error
        _ArrayAdd($array, $next[6])
        $array[0] += 1
    Until $error
    _FTPClose($first)
    Return $array
EndFuncoÝ÷ Ù»­ò.±è­¶§i×h­×¥z×~)^¶§ºÇ¢¶+]¡ë'ßÛkzÛ«©î¥Ö­yÛޮȨíçè׫jr&jG¢¶·­º¹Úê]j×½êìöZ§"Úò¶¬ÚÞ¶êç³F®¶­sbb33c·&VED2ÒgV÷C¶fÆRçGBgV÷C°¢b33c¶F"ÒgV÷C²ògV÷C°¢b33c¶æWvæÖRÒgV÷C¶fÆS"çGBgV÷C°¥ôeE&VæÖTfÆRb33c´6öææV7FöâÂb33c¶F"fײb33c·&VED2Âb33c¶F"fײb33c¶æWvæÖR

I am sure that the file exists. What am I doing wrong?

3. How can I get the download path of a file?

Thanks in advance.

Verify that the ftp is open like that

$dllhandle = DllOpen('wininet.dll')

$Open = _FTPOpen ('MyFTP Control',0)

If @error Then Failed("Open")

$Conn = _FTPConnect ($Open, $server,$username,$pass,21,1, 0x08000000,0)

If @error Then Failed("Connect")

Share this post


Link to post
Share on other sites

I'm sure it's open.

Yes but verify that you enter in passive mode (0x8000000), main of the problem comes from that's

Share this post


Link to post
Share on other sites

I tried putting "0x0000008" in the Flags part of FTP connect and it didn't help. I still haven't figured out or fixed any of the questions...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0