Jump to content
Sign in to follow this  
wedsxcrfv

FTP file send problem

Recommended Posts

wedsxcrfv

Well, i have no idea how to use the FTP.au3

Heres my script:

#include <FTP.au3>
$server = '********.*********.***'
$username = '******'
$pass = '*********'

$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FtpPutFile($Conn, @ScriptDir & '/security.file','/password.txt')
$Ftpc = _FTPClose($Open)

I am not English... But that matters nothing, I'm Dutch and i SPEAK English so it doesnt matter :P

Share this post


Link to post
Share on other sites
houseonfire

Im having a problem also.

#include <Array.au3>
#include <ftp.au3>
PluginOpen("C:\Program Files\AutoIt3\Au3Zip.dll")



$sPath = @MyDocumentsDir&"\My Received Files\"


Func _FileFind($sPath, $Mask, $Flag=0)
    If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(1, 0, -1)
   
    Local $RetPathArr[1], $FindNextFile, $CurrentPath, $SubDirFindArr, $Ubound = 0
    If StringInStr($Mask, "*") Then $Mask = StringReplace($Mask, "*.", "")
   
    $sPath = StringRegExpReplace($sPath, '\\+ *$', '\')   
    Local $FindFirstFile = FileFindFirstFile($sPath & "\*.*")
    If @error = 1 Then Return SetError(2, 0, 0)
    If $FindFirstFile = -1 Then Return SetError(3, 0, 0)
   
    While 1
        $FindNextFile = FileFindNextFile($FindFirstFile)
        If @error = 1 Then ExitLoop
        $CurrentPath = $sPath & "\" & $FindNextFile
        If $Flag = 1 And StringInStr(FileGetAttrib($CurrentPath), "D") Then
            $SubDirFindArr = _FileFind($CurrentPath, $Mask, $Flag)
            If IsArray($SubDirFindArr) Then
                For $i = 1 To UBound($SubDirFindArr)-1
                    $Ubound = UBound($RetPathArr)
                    ReDim $RetPathArr[$Ubound+1]
                    $RetPathArr[$Ubound] = $SubDirFindArr[$i]
                Next
            EndIf
        Else
            If $Mask = "*" Or $FindNextFile = $Mask Or StringRegExpReplace($CurrentPath, '^.*\.', '') = $Mask Then
                $Ubound = UBound($RetPathArr)
                ReDim $RetPathArr[$Ubound+1]
                $RetPathArr[$Ubound] = $CurrentPath
            EndIf
        EndIf
    WEnd
    FileClose($FindFirstFile)   
   
    If $Ubound = 0 Then Return SetError(3, 0, 0)
    $RetPathArr[0] = $Ubound
    Return $RetPathArr
EndFunc




$ftpIP = 'zomg'
$ftpUser = 'zomg'
$ftpPass = 'zomg'


local $dllhandle = DllOpen('wininet.dll')

;Open FTP Session
$Session = _FTPOpen("FTP")
if @error then
    MsgBox(16,"Error","FTP Session Failed to open.")
    DllClose($dllhandle)
    Exit
EndIf

;Connect to FTP server
$ftpSession = _FTPConnect($Session,$ftpIP,$ftpUser,$ftpPass,0,1,0x08000000)
if @error then
    MsgBox(16,"Error","FTP Connection Failed" & @cr & "Please check you connection and FTP Settings")
    _FTPClose($Session)
    DllClose($dllhandle)
    Exit
EndIf

$FileList= _FileFind($sPath, "*.xml", 1) 
If @Error Then
    MsgBox (0,"","No Files\Folders Found.")
    DllClose($dllhandle)
    Exit
EndIf

For $x = 1 to $FileList[0]
    ConsoleWrite($FileList[$x] & " tranferred to:" & "www/images/"&$FileList[$x]& @CRLF)
   _FTPPutFile ($ftpSession ,$FileList[$x], "www/images/"&$FileList[$x], $ftpUser, $FTPpass)
    If @error Then
        MsgBox(0,"_FTPPutFile @error",@error)
        DllClose($dllhandle)
        Exit
    EndIf
Next

It just returns a 0 and then a -1

Share this post


Link to post
Share on other sites
PsaltyDS

Im having a problem also.

It just returns a 0 and then a -1

Which part fails? If _FileFind() is working fine, then you can eliminate half the script for simplification of the case by just statically passing a file path for testing. Conversely, if _FileFind() is failing you can debug that in isolation from the distraction of the FTP stuff.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
houseonfire

Its the _FTPPutFile. When I open that up it just says 0 in a message box, then a -1 in a new message box.

Then on the console, it says it was sent.. When in reality, it wasn't.

Share this post


Link to post
Share on other sites
PsaltyDS

Its the _FTPPutFile. When I open that up it just says 0 in a message box, then a -1 in a new message box.

Then on the console, it says it was sent.. When in reality, it wasn't.

Well, the ConsoleWrite() is being done BEFORE the _FTPPutFile(), so it's not diagnostic.

Try that part this way:

For $x = 1 To $FileList[0]
    ConsoleWrite("Debug: Begin _FTPPutFile():" & @LF & _
        @TAB & "Source " & $x & " = " & $FileList[$x] & @LF & _
        @TAB & "Dest = www/images/" & $FileList[$x] & @LF & _
        @TAB & "$ftpUser = " & $ftpUser & @LF & _
        @TAB & "$ftpPass = " & $ftpPass & @LF)
    _FTPPutFile($ftpSession, $FileList[$x], "www/images/" & $FileList[$x], $ftpUser, $ftpPass)
    If @error Then
        MsgBox(0, "_FTPPutFile @error = ", @error)
        ExitLoop
    Else
        ConsoleWrite("Debug: _FTPPutFile() successfull." & @LF)
    EndIf
Next

; Done
DllClose($dllhandle)

Should get more useful info on the Console.

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
houseonfire

Thanks for that.

Now i just need to figure out why it doesnt make it to the

ConsoleWrite("Debug: _FTPPutFile() successfull." & @LF)

..

Returns a 0 and then a -1 ..

Share this post


Link to post
Share on other sites
PsaltyDS

Thanks for that.

Now i just need to figure out why it doesnt make it to the

ConsoleWrite("Debug: _FTPPutFile() successfull." & @LF)

..

Returns a 0 and then a -1 ..

What does "Returns a 0 and then a -1" mean? What returns it? Where are you seeing it?

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
PsaltyDS

Pops up in text boxes

That's what I don't understand. The MsgBox() functions are behind tests for @error. If @error = 0, how are you getting pop ups?

What are the titles of the pop ups? Which line of the script in post #3 is producing 0, and then which is producing -1?

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×