Sign in to follow this  
Followers 0
hoppy

Progresbar With Ftp Upload

10 posts in this topic

Hey, I'm probably missing the obvious thing here, but could someone please point it out for me why this isn't working as it should.

The upload itself works fine, but am trying to build in a progressbar but it doesn't show.

#include <FTP.au3>

$server = 'server'
$username = 'login'
$pass = 'pasw'
$SourceFile ='file1'
$SourceSize = FileGetSize($SourceFile)
$DestFileSize = 1

$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpd = _FTPDelFile($Conn, 'file2')
$Ftpp = _FtpPutFile($Conn, $SourceFile, 'file2')

ProgressOn("Uploading", "")
    While $DestFileSize < $SourceSize
        Sleep(100)
        $DestFileSize = InetGetSize("file2")
        $Percent = round(($DestFileSize/$SourceSize)*100,0)
        ProgressSet($Percent, $Percent & "% done")
    WEnd
ProgressOff()
msgbox (blabla bla)

Why doesn't the progressbar run?

Share this post


Link to post
Share on other sites



Hey, I'm probably missing the obvious thing here, but could someone please point it out for me why this isn't working as it should.

The upload itself works fine, but am trying to build in a progressbar but it doesn't show.

#include <FTP.au3>

$server = 'server'
$username = 'login'
$pass = 'pasw'
$SourceFile ='file1'
$SourceSize = FileGetSize($SourceFile)
$DestFileSize = 1

$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpd = _FTPDelFile($Conn, 'file2')
$Ftpp = _FtpPutFile($Conn, $SourceFile, 'file2')

ProgressOn("Uploading", "")
    While $DestFileSize < $SourceSize
        Sleep(100)
        $DestFileSize = InetGetSize("file2")
        $Percent = round(($DestFileSize/$SourceSize)*100,0)
        ProgressSet($Percent, $Percent & "% done")
    WEnd
ProgressOff()
msgbox (blabla bla)

Why doesn't the progressbar run?

I don't know AutoIT's _FtpPutFile() function, but if it pauses the script until the transfer is complete, then destination size is already equal to source size before your While test is done... :think:

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

anyone another idea or method to upload a file,

but with which a progressbar can be used?

Share this post


Link to post
Share on other sites

anyone another idea or method to upload a file,

but with which a progressbar can be used?

Did you determine if the script was paused by _FtpPutFile()? If it is, you will need a seperate process, via a second script instance or perhaps AdLib(), that will periodically update the progress bar.

:think:


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

Did some experementing with the loop, but it always came after the upload seem to be done.

So (as far as) I can say autoit halts till the job is done.

Will try to make a workaround and give adlib a shot (never worked with it before)

Thanks for your help and support.

Share this post


Link to post
Share on other sites

Even adlib() seems to be pauzed by the upload command.

Did some testing with a simple tooltip()

Anyone any more ideas

Share this post


Link to post
Share on other sites

Even adlib() seems to be pauzed by the upload command.

Did some testing with a simple tooltip()

Anyone any more ideas

Hmm... :think:

Then you are back to a seperate script to run the progress bar. You can code a code a script that receives source and destination file paths as commandline arguments, then presents a progress bar comparing the two. Then your original script would kick off the progress script first, then the ftp transfer. While the original script waited for the ftp transfer, the progress script would present your progress bar.

"neogia" (Snidely Whiplash with a kidnapped burrito), wrote a library to simulate multi-threading in an AutoIT script. You could check that out at thread #23545, but for quick and dirty it might be easier just to code a seperate script.

:(


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

Sorry to wake a very old thread, but the title is perfect and it hasn't been solved as far as I can see. I created a separate script which accepts command line parameters for the progress bar, but now how do I keep it in sync with (pass it) the actual number of bytes being uploaded by _FTPputFile()?

Share this post


Link to post
Share on other sites

There is InternetSetStatusCallback function in wininet.dll, but i can not make it work :)

$server = 'server.com'
$username = 'username'
$pass = 'pass'
$Port = 21

$File = @ScriptDir & '\Test.txt'

$hDll = DllOpen('wininet.dll')
$hCallBack = DllCallbackRegister("Test_Func", "int", "hwnd;int;int;ptr")
$ptr = DllCallbackGetPtr($hCallBack)

$Open = _FTPOpen('MyFTP Control', 0)

$pInetStatus = DllCall('wininet.dll', 'int', 'InternetSetStatusCallback', 'hwnd', $Open, 'ptr', $ptr)

;$ptr = 0 ;uncomment this, and all uploaded correctly
$Conn = _FTPConnect($Open, $server, $username, $pass, $Port, 1, 0, $ptr, $hDll)
$Ftpp = _FtpPutFile($Conn, $File, 'Test.txt', 0, $ptr, $hDll)
$Ftpc = _FTPClose($Open)

DllCallbackFree($hCallBack)
DllClose($hDll)


Func Test_Func($hWnd, $nMsg, $wParam, $lParam)
    ConsoleWrite("Func is called" & @LF)
EndFunc


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

Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 1, $l_Service = 1, $l_Flags = 0, $l_Context = 0, $hDll = -1)
    
    Local $hDllOpen = $hDll
    
    If $hDll = -1 Then $hDllOpen = DllOpen('wininet.dll')
    
    Local $ai_InternetConnect = DllCall($hDllOpen, 'int', 'InternetConnect', 'hwnd', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'ptr', $l_Context)
    If @error OR $ai_InternetConnect[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    If $hDll = -1 Then DllClose($hDllOpen)
    
    Return $ai_InternetConnect[0]
EndFunc

Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0, $hDll = -1)
    Local $hDllOpen = $hDll
    
    If $hDll = -1 Then $hDllOpen = DllOpen('wininet.dll')
    
    Local $ai_FTPPutFile = DllCall($hDllOpen, 'int', 'FtpPutFile', 'hwnd', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'dword', $l_Flags, 'ptr', $l_Context)
    If @error OR $ai_FTPPutFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    If $hDll = -1 Then DllClose($hDllOpen)
    
    Return $ai_FTPPutFile[0]
EndFunc

Func _FTPClose($l_InternetSession, $hDll = -1)
    
    Local $hDllOpen = $hDll
    
    If $hDll = -1 Then $hDllOpen = DllOpen('wininet.dll')
    
    Local $ai_InternetCloseHandle = DllCall($hDllOpen, 'int', 'InternetCloseHandle', 'hwnd', $l_InternetSession)
    If @error OR $ai_InternetCloseHandle[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    If $hDll = -1 Then DllClose($hDllOpen)
    
    Return $ai_InternetCloseHandle[0]
EndFunc

I am not sure what this mean:

dwContext

Pointer to a variable that contains the application-defined value that associates this search with any application data. This parameter is used only if the application has already called InternetSetStatusCallback to set up a status callback.

Where is from i take this pointer? from the callback register? not working :(.

If there is need to create structure, how do i know what is the "Struct" value?

I get here Exit Code: -1073741819

The callback function is called once, and then the script is crashes.

I sure that i am doing here something (maybe all? ;) ) wrong, but this is my first attempt to "translate" MSDN stuff :D


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

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