Sign in to follow this  
Followers 0
VeeDub

FtpPutFile won't upload

3 posts in this topic

Hi,

My first attempt at using FTP.au3 is not working, so I am probably doing something wrong, hopefully something that is easy to spot. Although I notice a couple of other people have posted similar threads.

Here's the code that I am using:

AutoItSetOption("TrayIconDebug",1)

    $server = 'myserver'
    $username = 'myuser'
    $pass = 'mypass'

    $Open = _FTPOpen('MyFTP Control')
    If $Open = 0 Then
        MsgBox(0,"FTP_Open Error",@error)
    Else
        MsgBox(0,"FTP Open completed","OK")
    EndIf   

    $Conn = _FTPConnect($Open, $server, $username, $pass)
    If $Conn = 0 Then
        MsgBox(0,"FTP_Connect Error",@error)
    Else
        MsgBox(0,"FTP Connect completed","OK")
    EndIf   

    $Ftpp = _FtpPutFile($Conn, 'C:\WINDOWS\Notepad.exe', 'notepad.exe')
    $Error = @error
    $lasterror = DllCall("kernel32.dll","int","GetLastError")
    msgbox(0,"LAST ERROR",$lasterror[0])
    If $Ftpp = 0 Then
        MsgBox(0,"FTP_PutFile Error",$Error)
    Else
        MsgBox(0,"FTP Put completed","OK")
    EndIf   

    $Ftpc = _FTPClose($Open)

I know that the problem is with the code, because I can use a different FTP client and upload notepad.exe to the default directory on the FTP server OK.

When I run the script, it gets to the _FtpPutFile command and "hangs" for a few minutes before eventually continuing. $lasterror is: 0, $Error is: -1

The logs on the FTP Server report that the after between 5 - 10 minutes the connection times out. No bytes are ever sent.

I am using version 3.2.0.1 of Autoit.

Two other questions:

1. This thread (post #1) refers to a passive flag. Would this be using a modified ftp.au3, otherwise I don't understand how this works.

2. When sending binary files do I need to be setting any flags?

Thanks

VeeDub

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The logs on the FTP Server report that the after between 5 - 10 minutes the connection times out. No bytes are ever sent.

Disable your desktop firewall and try again. If it works, you can think about passive ftp. If it still does not work, passive ftp won't help.

EDIT: For passive FTP see here:

_FTPConnect(): http://www.autoitscript.com/forum/index.ph...ost&id=3314

InternetConnect: http://msdn.microsoft.com/library/default....rnetconnect.asp

You need to pass INTERNET_FLAG_PASSIVE to InternetConnect!

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(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 *

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Disable your desktop firewall and try again. If it works, you can think about passive ftp. If it still does not work, passive ftp won't help.

You need to pass INTERNET_FLAG_PASSIVE to InternetConnect!

Thanks Kurt, using Passive Mode did the trick. I just need to sort out the Binary Flag now.

Edit: Figured this out by referring to MSDN and have posted the revised script. I downloaded notepad2.exe and it worked fine.

Here's the revised script for anyone who comes across this thread later

#include "FTP.au3"

    AutoItSetOption("TrayIconDebug",1)

    $server = 'your FTP server'
    $username = 'your username'
    $pass = 'your password'
    
    Global $INTERNET_FLAG_PASSIVE = 0x08000000
    Global $FTP_TRANSFER_TYPE_UNKNOWN = 0x00000000
    Global $FTP_TRANSFER_TYPE_ASCII = 0x00000001
    Global $FTP_TRANSFER_TYPE_BINARY = 0x00000002


    $Open = _FTPOpen('MyFTP Control')
    If $Open = 0 Then
        MsgBox(0,"FTP_Open Error",@error)
    Else
        MsgBox(0,"FTP Open completed","OK")
    EndIf   

    $Conn = _FTPConnect($Open, $server, $username, $pass, 21, 1, $INTERNET_FLAG_PASSIVE)
    If $Conn = 0 Then
        MsgBox(0,"FTP_Connect Error",@error)
    Else
        MsgBox(0,"FTP Connect completed","OK")
    EndIf   

    $Ftpp = _FtpPutFile($Conn, 'C:\WINDOWS\Notepad.exe', 'notepad2.exe',$FTP_TRANSFER_TYPE_BINARY)
    $Error = @error
    $lasterror = DllCall("kernel32.dll","int","GetLastError")
    msgbox(0,"LAST ERROR",$lasterror[0])
    If $Ftpp = 0 Then
        MsgBox(0,"FTP_PutFile Error",$Error)
    Else
        MsgBox(0,"FTP Put completed","OK")
    EndIf   

    $Ftpc = _FTPClose($Open)

Cheers,

VW

Edited by VeeDub

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