Jump to content

FTP Upload won't work?


Recommended Posts

#include <FTP.au3>

$server = "BLANK"
$username = "BLANK"
$pass = "BLANK"

$Open = _FTPOpen("ftpupload")
consolewrite( "Open: " & $Open & @crlf )
$Conn = _FTPConnect($Open, $server, $username, $pass)
consolewrite( "Connect: " & $Conn & @crlf )
$Ftpp = _FtpPutFile($Conn, @ScriptDir&"\test.txt", "/htdocs/pinner")
consolewrite( "Put Result: " & $Ftpp & @crlf )
$Ftpc = _FTPClose($Open)

It won't work? Open: [RANDOMNUMBERS], Connect: [SAME RANDOM NUMBERS], and finally Put Result, which equals zero. (Put Result = 0) < consolewrite.

 

Why won't it work? Please.

Link to comment
Share on other sites

Why using the old FTP.au3. Use the FTPEx.au3, here the example for _FTP_FilePut:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <FTPEx.au3>

Opt('MustDeclareVars', 1)

_example()

Func _example()
    Local $s_ServerName = '127.0.1' ;dieser Server existiert nicht
    Local $s_Username = "Bert"
    Local $s_Password = "Test"

    Local $s_LocalFile = @ScriptDir & "\_FTP_FilePut.au3"
    Local $s_RemoteFile = "/AutoIt3.My/_FTP_FilePut.au3"
    Local $i_Passive = 0
    Local $l_InternetSession, $l_FTPSession, $errOpen, $errFTP

    $l_InternetSession = _FTP_Open('AuoItZilla') ;Öffnet eine FTP Sitzung
    $errOpen = @error
    If Not @error Then
        $l_FTPSession = _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive) ;Verbindet zu einem FTP Server
        $errFTP = @error
        If Not @error Then
            If _FTP_FilePut($l_FTPSession, $s_LocalFile, $s_RemoteFile) Then
                ConsoleWrite("Upload: erfolgreich"  & @CRLF)
            Else
                ConsoleWrite("Upload: fehlgeschlagen " & " " & @error & @CRLF)
            EndIf
        Else
            MsgBox(0, "Connect", "fehlgeschlagen")
            ConsoleWrite("Connect: " & " " & $errFTP & @CRLF)
        EndIf
    Else
        MsgBox(0, "Open", "fehlgeschlagen")
        ConsoleWrite("Open " & " " & $errOpen & @CRLF)
    EndIf
    _FTP_Close($l_FTPSession)        ;schliesst die FTP-Sitzung
    _FTP_Close($l_InternetSession)   ;schliesst die Internet-Sitzung
EndFunc   ;==>_example

i wrote this example for the german helpfile long (AutoIt 3.3.6.3) time ago and it works still today with AutoIt 3.3.12.0 

 

 

Edited by AutoBert
removed attached files (bug in board)
Link to comment
Share on other sites

It comes with AutoIt3 download, FTPEx is a standard UDF include.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I tried the script, and I get an error that says "Upload: fehlgeschlagen  -1".The servername, username and password is a hundred

percent correct.

 

Local $s_LocalFile = @ScriptDir & "\test.txt"
 Local $s_RemoteFile = "/htdocs/pinner/test.txt"

It doesn't work? I don't understand. I've also tried RemoteFile as just /htdocs/pinner/ and so on. Please help!

Link to comment
Share on other sites

Is the FTP server a secure FTP server (SFTP)? If it is, then the FTP functions in AutoIt won't work.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 weeks later...

No, I don't think so.

What should I put in the remotefile place<?

The whole Path to the file. All folders in the Path must exist. I have expanded my example:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <FTPEx.au3>

Opt('MustDeclareVars', 1)

_example()

Func _example()
    Local $s_ServerName = '127.0.0.1' ;dieser Server existiert nicht
    Local $s_Username = "Bert"
    Local $s_Password = "Test"

    Local $s_LocalFile = @ScriptDir & "\FTP_FilePut.au3"
    Local $s_RemoteFile = "/AutoIt3.My/FTP_FilePut.au3"
    Local $i_Passive = 0
    Local $l_InternetSession, $l_FTPSession, $errOpen, $errFTP
    If Not FileExists($s_LocalFile) Then
        ConsoleWrite('Local File not found' & @CRLF)
        Exit
    EndIf
    $l_InternetSession = _FTP_Open('AuoItZilla') ;Öffnet eine FTP Sitzung
    $errOpen = @error
    If Not @error Then
        ConsoleWrite("Internet-Session opened" & @CRLF)
        $l_FTPSession = _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive) ;Verbindet zu einem FTP Server
        $errFTP = @error
        If Not @error Then
            ConsoleWrite("connected to " & $s_ServerName & @CRLF)
            If _FTP_FilePut($l_FTPSession, $s_LocalFile, $s_RemoteFile) Then
                ConsoleWrite("Upload: erfolgreich" & @CRLF)
            Else
                ConsoleWrite("Upload: fehlgeschlagen " & " " & @error & @CRLF)
                ConsoleWrite("Check all Folders in Remotepath, they must exist before uploading!" & @CRLF)
            EndIf
        Else
            MsgBox(0, "Connect", "fehlgeschlagen")
            ConsoleWrite("Connect: " & " " & $errFTP & @CRLF)
        EndIf
    Else
        MsgBox(0, "Open", "fehlgeschlagen")
        ConsoleWrite("Open " & " " & $errOpen & @CRLF)
    EndIf
    _FTP_Close($l_FTPSession) ;schliesst die FTP-Sitzung
    _FTP_Close($l_InternetSession) ;schliesst die Internet-Sitzung
EndFunc   ;==>_example

So you can see that session is opened (only when local file exists), the session is connected and if FilePut false the message that all Folders must exists.

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...