Jump to content

what is wrong with my script?


mads3n
 Share

Recommended Posts

#include <GuiConstants.au3>


$mainwindow = GuiCreate("Secret L-Upl v.1", 400, 160)

$oobutton = GUICtrlCreateButton ( "Vælg fil", 20, 5, 180, 60, 0x0300)

$gembutton = GUICtrlCreateButton ( "GEM / Upload", 200, 5, 180, 60, 0x0300)

GuiCtrlCreateLabel("Filnavn:", 10, 80)

$label = GuiCtrlCreateLabel("Ingen fil valgt", 55, 80, 345, 40)

Func _FTPput($s_p_Host, $s_p_PathFile, $s_p_Acc, $s_p_Pwd, $s_p_Cd = '', $i_p_Check = 0, $s_p_Aftp = '')
    
    ; Declaring local variables.
    Local $i_p_Return
    
    ; Creating a random nummber to minimize the chance of writing to an existing file.
    Local $i_p_Random = Random(100000000, 999999999, 1)
    
    ; Creating the file.
    Local $h_p_CmdFile = FileOpen(@TempDir & "\FTPcmds" & $i_p_Random & ".txt", 1)
    
    ; Check if wildcards are used.
    If StringInStr($s_p_PathFile, "*") <> 0 Then Local $i_p_Check = 0
    
    ; Getting the path and the filename from $s_p_PathFile.
    Local $s_p_Path = StringTrimRight($s_p_PathFile, StringLen($s_p_PathFile) - StringInStr($s_p_PathFile, "\", 0, -1) + 1)
    Local $s_p_File = StringTrimLeft($s_p_PathFile, StringInStr($s_p_PathFile, "\", 0, -1))
    
    ; Create an FTP command file if the file is sucsesfully created.
    If $h_p_CmdFile <> -1 Then
        
        ; Writing the account and password.
        FileWriteLine($h_p_CmdFile, $s_p_Acc & @CRLF)
        FileWriteLine($h_p_CmdFile, $s_p_Pwd & @CRLF)
        
        ; Set the transfermode to binary
        FileWriteLine($h_p_CmdFile, "binary" & @CRLF)
        
        ; Additional FTP commands passed to the function are actioned here.
        If $s_p_Aftp <> '' Then FileWriteLine($h_p_CmdFile, $s_p_Aftp & @CRLF)
            
        ; Making the destination dir if it doesnot exist
        FileWriteLine($h_p_CmdFile, 'mkdir ' & $s_p_Cd & @CRLF)
        
        ; Set the destination dir if one is given. Else 'root' will be used.
        If $s_p_Cd <> '' Then FileWriteLine($h_p_CmdFile, "cd " & $s_p_Cd & @CRLF)
        
        ; Set the local directory and send the files.
        FileWriteLine($h_p_CmdFile, "lcd " & $s_p_Path & @CRLF)
        FileWriteLine($h_p_CmdFile, "mput " & $s_p_File & @CRLF)
        
        ; If $i_p_Check is set to 1 it will get the transferred file back to a check area so we can confirm it worked.
        If $i_p_Check = 1 Then
            FileWriteLine($h_p_CmdFile, "lcd " & @TempDir & @CRLF)
            FileWriteLine($h_p_CmdFile, "mget " & $s_p_File & @CRLF)
        EndIf
        
        ; Closes the FTP connecetion and exits the FTP program.
        FileWriteLine($h_p_CmdFile, "close" & @CRLF)
        FileWriteLine($h_p_CmdFile, "quit" & @CRLF)
        
        ; Closes the file.
        FileClose($h_p_CmdFile)
        
    EndIf
    
    ; Start FTP with the cmdfile to transfer the file(s) concerned.
    RunWait(@ComSpec & " /c " & 'ftp -v -i -s:' & @TempDir & "\FTPcmds" & $i_p_Random & ".txt " & $s_p_Host, "", @SW_HIDE)
    
    ; Setting the return value's.
    If $i_p_Check = 1 And Not FileExists(@TempDir & "\" & $s_p_File) Then
        $i_p_Return = -1
    ElseIf $i_p_Check = 1 And FileExists(@TempDir & "\" & $s_p_File) Then
        $i_p_Return = 1
    Else
        $i_p_Return = 0
    EndIf
    
    ; Delete the temp files.
    FileDelete(@TempDir & "\" & $s_p_File)
    FileDelete(@TempDir & "\FTPcmds" & $i_p_Random & ".txt")
    
    ; Return the returnvalue.
    Return $i_p_Return
    
EndFunc   ;==>_FTPput

GUISetState(@SW_SHOW)

While 1
   $msg = GUIGetMsg()

   Select
   

      Case $msg = $GUI_EVENT_CLOSE
        ;Exit the script
         Exit
         

      Case $msg = $oobutton
                $navn = FileOpenDialog ("Vælg fil:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "(*.*)")
                If @error Then ContinueLoop
                GUICtrlSetData($label, $navn)


              Case $msg = $gembutton
              _FTPput('********', $navn, '******', '******')
              MsgBox(64, "INFO", "Filen er nu opdateret")

   EndSelect

WEnd

This was supposted to upload a selected file to my ftp-server...

can anyone tell me why it only uploads an empty file?

Mads3n.dk
Link to comment
Share on other sites

This was supposted to upload a selected file to my ftp-server...

can anyone tell me why it only uploads an empty file?

please post the created FTP commands file.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

There is something else wrong here beside the script...

@OP,

For future reference, when posting a thread , make its title remotely pertinent to question/subject you are posting about.

This is the support section of the forum, its meant for questions, so naming a thread "I Have A Problem", or "Question", or "Help Me My, Code Doesn't Work", or "Noob Requesting Assistance" Is redundant, and makes it harder for anyone else who has the same/similar questions as you to find the answer by searching the forums, which in turn means people often have to make extra threads and people who are answering the threads just end up repeating themselves several times over.

It is counter-productive.

Link to comment
Share on other sites

There is something else wrong here beside the script...

@OP,

For future reference, when posting a thread , make its title remotely pertinent to question/subject you are posting about.

This is the support section of the forum, its meant for questions, so naming a thread "I Have A Problem", or "Question", or "Help Me My, Code Doesn't Work", or "Noob Requesting Assistance" Is redundant, and makes it harder for anyone else who has the same/similar questions as you to find the answer by searching the forums, which in turn means people often have to make extra threads and people who are answering the threads just end up repeating themselves several times over.

It is counter-productive.

Well, He did mention in the description "-ftp upload-".
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

ah..im sorry :whistle: didnt think of that..

i got the ftp side of my script from here:

http://www.autoitscript.com/forum/index.php?showtopic=10251

There is a new FTP UDF. Use that instead!

http://www.autoitscript.com/forum/index.php?showtopic=12473

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

hmm :/ ive put the new in.. and now it doesnt upload a file at all..

it looks like this:

$server = '***'
$username = '***'
$pass = '***'
$s_Agent = 'minftp'
$i_ServerPort = '0'


Func _FTPOpen($s_Agent, $l_AccessType = 1, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0)
    
    Local $ai_InternetOpen = DllCall('wininet.dll', 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
    If @error OR $ai_InternetOpen[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
        
    Return $ai_InternetOpen[0]
    
EndFunc ;==> _FTPOpen()

Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)
    
    Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $server, 'int', $i_ServerPort, 'str', $username, 'str', $pass, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_InternetConnect[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
            
    Return $ai_InternetConnect[0]
    
EndFunc ;==> _FTPConnect()

Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $navn, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_FTPPutFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_FTPPutFile[0]
    
EndFunc ;==> _FTPPutFile()

Func _FTPClose($l_InternetSession)
    
    Local $ai_InternetCloseHandle = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $l_InternetSession)
    If @error OR $ai_InternetCloseHandle[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_InternetCloseHandle[0]
    
EndFunc ;==> _FTPClose()


                $Open = _FTPOpen('minftp')
                $Conn = _FTPConnect($Open, $server, $username, $pass)
                $Ftpp = _FtpPutFile($Conn, $navn, '')
                $Ftpc = _FTPClose($Open)

ive got some problems by getting the hang of this script..

and yes.. im a noob.. lol ^^ hope you guys can help

Mads3n.dk
Link to comment
Share on other sites

hmm :/ ive put the new in.. and now it doesnt upload a file at all..

it looks like this:

$server = '***'
$username = '***'
$pass = '***'
$s_Agent = 'minftp'
$i_ServerPort = '0'
Func _FTPOpen($s_Agent, $l_AccessType = 1, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0)
    
    Local $ai_InternetOpen = DllCall('wininet.dll', 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
    If @error OR $ai_InternetOpen[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
        
    Return $ai_InternetOpen[0]
    
EndFunc ;==> _FTPOpen()

Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)
    
    Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $server, 'int', $i_ServerPort, 'str', $username, 'str', $pass, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_InternetConnect[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
            
    Return $ai_InternetConnect[0]
    
EndFunc ;==> _FTPConnect()

Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $navn, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_FTPPutFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_FTPPutFile[0]
    
EndFunc ;==> _FTPPutFile()

Func _FTPClose($l_InternetSession)
    
    Local $ai_InternetCloseHandle = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $l_InternetSession)
    If @error OR $ai_InternetCloseHandle[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_InternetCloseHandle[0]
    
EndFunc ;==> _FTPClose()
                $Open = _FTPOpen('minftp')
                $Conn = _FTPConnect($Open, $server, $username, $pass)
                $Ftpp = _FtpPutFile($Conn, $navn, '')
                $Ftpc = _FTPClose($Open)

ive got some problems by getting the hang of this script..

and yes.. im a noob.. lol ^^ hope you guys can help

Maybe the _FtpPutFile($Conn, $Navn, ") For 1, Theres only one ", and two, I believe you have to have a filname there. for example. _FtpPutFile($Conn, $Navn, "notepad.exe")
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Maybe the _FtpPutFile($Conn, $Navn, ") For 1, Theres only one ", and two, I believe you have to have a filname there. for example. _FtpPutFile($Conn, $Navn, "notepad.exe")

ah.. ok :/ can i get the script to use the name of the file i've allready choosen to upload in some way?

ex If i upload a file named Test.exe

then just get the script to keep the existing name.

im using:

;Check if user clicked on the "OK" button
      Case $msg = $oobutton
                $navn = FileOpenDialog ("Vælg fil:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "(*.*)")
                If @error Then ContinueLoop
                GUICtrlSetData($label, $navn)
oÝ÷ Ù©ÝƧ¶ëÓ~§jùíêÞ¶§Ü"ZÞ¶ê綰^¥«a¡ûayø¥x@ÈN{æb¶ëu«­¢+Ø)¥´ÀÌØíÍéÉ¥Ù°ÀÌØíÍé¥È°ÀÌØíÍé9µ°ÀÌØíÍéáÐ($$$ÀÌØíQÍÐô}AÑ¡MÁ±¥Ð ÀÌØí¹Ù¸°ÀÌØíÍéÉ¥Ù°ÀÌØíÍé¥È°ÀÌØíÍé9µ°ÀÌØíÍéáФ(
Edited by mads3n
Mads3n.dk
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...