Sign in to follow this  
Followers 0
BananaFredSoft

BananaFTP - File Rename fixed!

10 posts in this topic

#1 ·  Posted (edited)

This is my FTP client. The green "Up" arrow brings you to the root directory. Selecting a folder and then clicking on the bar at the top of the file list will bring you into that folder.

Executable (with images): http://h1.ripway.com/bananafred/BananaFTP.exe

Bugs:

No file size (FTPGetFileSize wouldn't work for me)

Rename won't work (this function didn't work either...)

Can't get file download path (can't figure out how to do this)

Note: This is a beta. I created a help topic that asked how to fix the bugs and bumped it for a couple weeks and no one helped out, so I'll release it bugs and all.

Updates:

3/12/08: Port selection box added.

3/24/08: File Rename fixed.

Tell me what you think!

Code:

#include <FTP.au3>
#include <FTP2.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>

#include <GuiListView.au3>

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

If FileExists(@ScriptDir & "\up.bmp") = 0 Then
    FileInstall("G:\Au3 Programs\up.bmp", @ScriptDir & "\up.bmp")
EndIf

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("BananaFTP Sign-in", 310, 187, 193, 115)
$Combo1 = GUICtrlCreateCombo(IniRead(@ScriptDir & "\BananaFTPData.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 & "\BananaFTPData.data", "Main", "SavedUserName", ""), 64, 48, 233, 21)
$Label3 = GUICtrlCreateLabel("Password:", 8, 80, 53, 17)
$Input2 = GUICtrlCreateInput(_StringEncrypt(0, IniRead(@ScriptDir & "\BananaFTPData.data", "Main", "SavedPassword", ""), "12fHjkd73n"), 64, 80, 233, 21, $ES_PASSWORD)
$Label4 = GUICtrlCreateLabel("Server Port:", 8, 114)
$Port = GUICtrlCreateInput("21", 70, 112, 100)
$Button1 = GUICtrlCreateButton("Sign In", 8, 152, 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 & "\BananaFTPData.data", "Main", "SavedUserName", ""), GUICtrlRead($Combo1) <> IniRead(@ScriptDir & "\BananaFTPData.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 & "\BananaFTPData.data", "Main", "SavedServer", GUICtrlRead($Combo1))
                    IniWrite(@ScriptDir & "\BananaFTPData.data", "Main", "SavedUserName", GUICtrlRead($Input1))
                    If MsgBox(4, "Save password?", "Should the password be automatically entered from now on?") = 6 Then
                        IniWrite(@ScriptDir & "\BananaFTPData.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), GUICtrlRead($Port), 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("BananaFTP", 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)
$DirUp = GUICtrlCreateButton("", 10, 3, 25, 25, $BS_BITMAP)
GUICtrlSetImage($DirUp, @ScriptDir & "\up.bmp")
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, $dir & $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, $dir & 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, $dir & $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
                    $dload = _FTPGetFile($Connection, $dir & $readTC, @ScriptDir & "\" & $readTC)
                    If $dload Then
                        $del = _FTPDelFile($Connection, $dir & $readTC)
                        $put = _FTPPutFile($Connection, @ScriptDir & "\" & $readTC, $dir & $newname)
                    Else
                        $del = 0
                        $put = 0
                    EndIf
                    If $dload + $del + $put = 3 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 $DirUp
            $dir = "/"
            RedoList($dir)
        Case $ListView1
            $readread = StringTrimRight(GUICtrlRead(GUICtrlRead($ListView1)), 1)
            If $readread Then
                If StringInStr($readread, ".") = 0 Then
                    $dir = $dir & $readread
                    RedoList($dir)
                EndIf
            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 = "/")
    DllClose($handle)
    $handle = DLLOpen('wininet.dll')
    _FTPClose($Session)
    Global $Session = _FtpOpen("MyFTP Control")
    Global $Connection = _FTPConnect($Session, $Server, $UserName, $Password)
    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



It hammers when its unable to connect. I where just banned from one of my server, no worries, quick ssh through another server and flushing iptables fixed it.

Other that that it looks nice, and works nice as far as i tested it :)


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

Adding multiple port support would be great, i see its hardcoded port 21 now, adding either a regexp where you check address for "address:port", or a port input form.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

when running from the source i get the error that the includes go to deep,a nd to make sure they are not recurisive...


Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)-----------------------------------

Share this post


Link to post
Share on other sites

Where is the "FTP2.Au3"?

Looks like a great script btw :)

Share this post


Link to post
Share on other sites

wow BananaFredSoft.

think is possible to add support for :

- command line

- sync ftp -> local folder

good work,

m.

Share this post


Link to post
Share on other sites

what is this error *Error opening the file.:

#include <FTP.au3> *

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