Sign in to follow this  
Followers 0
BitByteBit

FTP PutFile

2 posts in this topic

I'm having trouble uploading a file, everything else works.

I think its something to do with this _FtpPutFile($Hand, $Read, "'"&'/FTP/'& $Input&"'")

This works fine.:

_FtpPutFile($Hand, 'C:\Windows\notepad.exe', '/Example3.exe')

But:

_FtpPutFile($Hand, $Read, '/')

Returns an error, I'm convinced it's to do read $Read.

#cs============================================================================
A Map Of The Handle Array:
[0]
[1]= wininet.dll handle from _FTPOpen()
[2]= Handle from _FTPOpen()
[3]= Handle from _FTPConnect()
[4]= FTPFileFindFirst dll struct handle
[5]= FtpFindFirstFile handle
#ce=============================================================================
#include <.FTP.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
$server = 'ftp.teammc.cc'
$username = 'scripting@teammc.cc'
$pass = 'pass'
$Hand = _FTPOpen('Doesnt Matter')

#Region ### START Koda GUI section ### Form=
;$FTP = GUICreate("FTP", 260, 280, 192, 124,$WS_EX_ACCEPTFILES)
$FTP = GUICreate("FTP", 260, 280, 192, 124,$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
GUISetBkColor(0x99B4D1)
$Status = GUICtrlCreateLabel("Not Connected", 68, 5, 106, 15, $SS_CENTER)
$Connect = GUICtrlCreateButton("Connect", 8, 184, 107, 25, $WS_GROUP)
$Disconnect = GUICtrlCreateButton("Disconnect", 8, 216, 107, 25, $WS_GROUP)
$List1 = GUICtrlCreateList("", 8, 20, 233, 149)
$Put = GUICtrlCreateInput("", 128, 184, 113, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
$Upload = GUICtrlCreateButton("Upload", 128, 216, 115, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _FTPClose($Hand)
            Exit
        Case $Connect
            Connect()
        Case $Disconnect
            Disconnect()
        Case $List1
            $File = GUICtrlRead($List1)
            DownloadFile()
        Case $Upload
            $Read = GUICtrlRead($Put)
            If $Read <> "" then
            $Read = "'" & $Read & "'"
            MsgBox(0,"!","Uploading: " & $Read)
            $Input = InputBox("File Name","Please type in the name of the file you're uploading.")
            Upload()
        Else
            MsgBox(0,"!","Please drag a file into the Input Box")
                EndIf
    EndSwitch
WEnd


Func Upload()
;MsgBox(0,"!","Uploading file: " & $Read)
$WASD  = $Read & " " &"'"& '/FTP/'& $Input&"'"
MsgBox(0,"",$WASD)
_FtpPutFile($Hand, $Read, "'"&'/FTP/'& $Input&"'") 
;_FtpPutFile($Hand, $Read, $Input)
;_FtpPutFile($Hand, 'C:\Windows\notepad.exe', '/Example3.exe')  
;_FtpPutFile($Hand, $Read,"'/" & $Input&"'")
;_FtpPutFile($Hand, $Read, '/') 
if @error then
msgbox(0,"Error","PutFile 3")
Else
MsgBox(0,"","Uploaded")
EndIf
;if @error then msgbox(0,"Error","Couln't upload file.")
;If not @error Then
;MsgBox(0,"" ," Uploaded file: "& $Read)
GetFileList()
;EndIf
EndFunc

Func Connect()
_FTPConnect($Hand, $server, $username, $pass)
if @error then GUICtrlSetData($Status,"Not Connected")
if not @error Then GUICtrlSetData($Status,"Connected")
GetFileList()
EndFunc

Func Disconnect()
_FTPClose($Hand)
GUICtrlSetData($Status,"Disconnected")
EndFunc

Func GetFileList()
$CDIR = _FtpSetCurrentDir($Hand,"/FTP/")
if $CDIR = 1  Then GUICtrlSetData($Status,"/FTP/")
$3 = False
$4 = False
$5 = False
$6 = False

$FIRSTFILEINFO= _FTPFileFindFirst($Hand,".") ;Start
if Not @error then
$1 = True
Else
$1 = False
EndIf


if $1 = True Then $SECONDFILEINFO = _FTPFileFindNext($Hand)
If not @error Then
$2 = True
Else
$2 = False
EndIf
If $2 = True Then $THIRDFILEINFO = _FTPFileFindNext($Hand)
If not @error Then
$3 = True
$DFI = $THIRDFILEINFO [10]
GUICtrlSetData($List1,$DFI)
EndIf


If $3 = True then $FOURTHFILEINFO= _FTPFileFindNext($Hand)
If not @error Then
$4 = True
$DFI = $FOURTHFILEINFO[10]
GUICtrlSetData($List1,$DFI)
EndIf
If $4 = True Then $FIFTHFILEINFO= _FTPFileFindNext($Hand)
If not @error then
$5 = True
$DFI = $FIFTHFILEINFO[10]
GUICtrlSetData($List1,$DFI)
EndIf
If $5 = True Then $SIXTHFILEINFO= _FTPFileFindNext($Hand)
If not @error then
$6 = True
$DFI = $SIXTHFILEINFO[10]
GUICtrlSetData($List1,$DFI)
EndIf



;$FIRSTFILEINFO= _FTPFileFindFirst($Hand,"")
;If not @error Then
;$DP = $FIRSTFILEINFO[10]
;GUICtrlSetData($List1,$DP)
;EndIf


;$SECONDFILEINFO= _FTPFileFindNext($Hand)
;if @error then;
    ;msgbox(0,"Error","_FTPFileFindNext")
;Else
;GUICtrlSetData($List1,$DP)
;EndIf
;if $CDIR = 0 Then GUICtrlSetData($Status,"Root Current Dir")
;_FTPGetFolderContents($Hand,"/FTP/",@DesktopDir&"\ftp udf test\",1)
EndFunc

Func DownloadFile()
;_FTPGetFile($Hand, '/FTP/' & $File, @ScriptDir & '\' & $File)
_FTPGetFile($Hand, '/FTP/' & $File, 'C:\' & $File,0,0,1)
if @error then msgbox(0,"Error","Unable to get file: "&$File )
If not @error Then
GUICtrlSetData($Status,$File & " Downloaded")
$File1 = "C:\" & $File
ShellExecute($File1)
EndIf
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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