Jump to content
Sign in to follow this  
DirkVDB

copy and replace single .txt file (automated drop & drag)

Recommended Posts

DirkVDB

As a student I am working since almost a year on a program wich should manage(create/replace/update/delete) different 'known' .txt files (fixed filenames)

This program is currently written in standard C++, after the files where downloaded and modified I was used to upload them manually with FileZilla

For more convenience as the paths are allways the same, I tried to automate this with AutoIT3, (lovely program should have known this before).

I had already written a small script to automate the sequence of "starting program, filling in server, user, password"

this connection script with FTP-server works perfectly established, files are visible

I also think that I have the right adres for the different trees (source/destination), but it seems after weeks of searching that it is

impossible to simply take a specific file at source on FTP server and move it to a specific path in my system directory

As I consider myself as a newbee on AutoIT I suppose the problem is in my code, I changed it many times but as long that I am not sure about the code, I can't check if it could be a path problem, and this keeps going on since a while. So can some one check my code ? and let me know what's wrong here ?

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.10.0

Author: Dirk

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; begin script :

MsgBox(64, "Starting", "Downloading Files")

Run("FileZilla.exe")

WinWaitActive("FileZilla")

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:1]", "MYftp.server.com")

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:2]", "user")

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:3]", "password")

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:4]", "21")

MsgBox(64, "CONNECTION", "Hello, server connection established !")

ControlClick("FileZilla", "", "[iD:122]")

WinWaitActive("MYftp.server.com - FileZilla")

MsgBox(64, "FTP-server", "Files are ready for download.")

; here it start to be tricky

; SysTreeView322 is the file tree on the FTP-server

; but I am not convinced that this is the right way to, and cursor position with mouseclick could also cause problem

$handle = ControlGetHandle("MYftp.server.com - FileZilla", "", "SysTreeView322")

MsgBox(64, "debug", "@GUI_DragId")

For $i = 0 to 9

If FileExists("/www/Filename.txt" & $i & "*.*") Then

; for convenience during developpement I put the files in the same directory as the program and created for testing a subfolder 'www'

FileCopy("/www/Filename.txt" & $i & "*.*", "C:\autoFTP\Files\www\Filename.txt")

EndIf

Next

; SysTreeView321 is the local file tree (c\)

; $handle = ControlGetHandle("FileZilla", "", "SysTreeView321")

MsgBox(64, "FTP-server", "File download was succesfull.") ;

WinClose("MYftp.server.com - FileZilla")

; end script :-)

Share this post


Link to post
Share on other sites
Squirrely1

...but it seems after weeks of searching that it is impossible to simply take a specific file at source on FTP server and move it to a specific path in my system directory...

Look in the help file under

AutoIt > Function Reference > Network Functions > InetGet

InetGet ( "URL" [,"filename" [, reload [, background]]] )

After you are logged-in to the server, it seems like this function would work - you probably want to use the "reload" flag set to 1, and the "filename" parameter set to the full filepath - a local destination.

_________________________

Another way to do this is to use:

#include <INet.au3>

_INetGetSource ( $s_URL )

AutoIt > User Defined Functions > INet Management

Here is the path to the UDF help - "C:\Program Files\AutoIt3\UDFs3.chm" on my machine.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites
DirkVDB

I have to admit that I didn't check on networking functions because the server conecton is already established with the use of FileZilla,

(for connection with FTP-server I needed PASV) so in order to avoid some malfunctin during connection....

; for info "MYftp-server.com - FileZilla" is the name of my window in FileZilla, it's not an attempt to contact any server

that's also why my script is focused on accessing those functions within the FileZilla GUI,

I think I will try to trigger the built-in functions of FileZilla to solve my problem

ControlFocus ( "MYftp-server.com - FileZilla", "", "[sysTreeView322]" )

: will put some changes here and program action by action like this

; ControlClick ( "MYftp-server.com - FileZilla", "", "[sysTreeView322]" , "left" )

ControlTreeView ( "MYftp-server.com - FileZilla", "", "[sysTreeView322]", "select", "[www]|[Filename.txt]" )

$flnme = "Filename.txt"

If FileExists("www/" & $flnme & "*.*") Then

FileCopy("www/" & $flnme & "*.*", "C:\autoFTP\Files\www\Filename.txt")

EndIf

any help with code example how to trigger functions in OTHER program-windows would be welcome and appreciated

Share this post


Link to post
Share on other sites
Squirrely1

I sincerely don't believe you can use the functions "FileExists" or "FileCopy" on a remote file, except perhaps if you have enough permissions on that server.

Also, the fifth parameter in your ControlTreeView is invalid.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites
DirkVDB

I am still checking, how to automate the build-in actions, it looks like the only way out,

but I would need some help how to visualize the current position/handling.

I found some script on this forum, but it bugged and could not return any parameter or value

So now I will probably go in the way like I have done here "ControlSend("CurrentWindowTitle", "", "[CLASS:Edit; INSTANCE:4]", "21")"

This was also a (working) trigger of a build-in function, only I didn't found yet how to do the same if I have instead of one single "OK" option a kind of drop down menu within the build-in control/button (like right click on mouse... do this), how to choose/select the right function, tried several options, no bugs, but nothing happens either

If I can find a solution on this last one, I can go further in my script. (I Googled and Googled but I only obtained some other programs, no script or snippet)

Share this post


Link to post
Share on other sites
DirkVDB

sorry, mean this "ControlClick("CurrentWindowTitle", "", "[iD:122]")"

Share this post


Link to post
Share on other sites
DirkVDB

enclosed a jpg to clarify the problem

<<<< text >>>>

root /www/ on FTP server

should select this root and download from here the file Filename.txt

then move the file to the directory on my PC

the file should replace the existing one and appear here

Normally the GUI allows me to visually select(1) the file, right mouse click(2), select the option(3) to transfer the file(4), and then asks confirmation(5) that I want to overwrite the file on my PC

(1) here I encounter the problem to select the file as the structure might change

(2) if selected I suppose there will be a function to this in AutoIT

(3) in this case its the first option

(4) transfer proceeds automatically

(5) should hit [ENTER] on default setting

post-35222-1209748900_thumb.jpg

Share this post


Link to post
Share on other sites
DirkVDB

I added following code :

; I tested it with the right names (MyCurrentWindow, MySourceMap, SystemWarningOverWritingFile, TargetFileAlreadyExists) it works perfect and smooth

ControlFocus("MyCurrentWindow", "MySourceMap", "[sysTreeView322]")

ControlClick("MyCurrentWindow", 2 ,"[CLASSNN:SysListView322]")

MouseClick("left", 657, 229, 1)

MouseClick("left", 694, 309, 1)

MouseClick("left", 653, 606, 1)

MouseClick("right", 653, 606, 1)

MouseClick("left", 672, 614, 1)

WinWaitActive("SystemWarningOverWritingFile")

ControlClick("TargetFileAlreadyExists", "", "[iD:5100]")

Instead of programming it with mousepositions, I would like to have a generic more reliable code,

supporting any case of screensize (minimize/maximize...)

Share this post


Link to post
Share on other sites
MikeP

Hi. You don't like mouse coordinates ? then use the keyboard ! :)

I won't code it but will give you hints on how to do this since this is pretty easy.

When you start FileZilla the cursor focus is on the login.. after you login the cursor is on source path..

Just send your source path with Send* since you said it was always the same.. then Send("{ENTER}")

Then : Send("{TAB}") 3 times get you to the destination path adress bar..

same.. Send your destination path and Send("{ENTER}") to confirm.. use Sleep() as it can take some time to load.

Then Send("+{TAB}") 2 times (shift tab) to come back to the first directory of your source path..

then send a right clic with Mouseclick("right")** and send a down arrow key with Send("{DOWN}").. then Send("{ENTER}") to confirm and it will upload your directory

adapt this to your Filezilla version and GUI of course..we might not have the same

* what I would do is put your sourcepath in a global var : $sourcePath = "C:\blahblahb"

then put this in the clipboard with ClipPut($sourcePath).. then send a Send("{^v}") to paste it in your Filezilla source address bar.. same method with destination path.

** actually you would have to locate the current selected directory to do that right-clic.. (probably with ControlGetFocus and so on..) Personnaly I have a key which does the same to the left on my right ctrl key .. but I don't know if your keyboard got it or not.. and you gotta find the code for it but it's not that hard. Here's how my keyboard is, and I'm talking about the AppsKey:

CTRL WinKey Alt SPACEBAR AltGr WinKey AppsKey CTRL

Edited by MikeP

Share this post


Link to post
Share on other sites
DirkVDB

I tried something like this, but without succes the program returned several errors, and changed '.' with ';'

Will sleep over it tonight (it's past midnight here) I will work on it tomorrow with fresh mind,

I know this should work, it's as simple as 1 + 1, if you have the right syntax you can win any war :-)

But right now my brain is overloaded with a few hundreds of non-working codelines,

I checked and double checked the instances and classes.... a few hours long... after this directly

accessing the right filepath looks simple, but for some reason a physical path that I have copied from a live connection,

just copy-paste (several times) is refused during automation by FileZilla for some unknown reason, then I added {BACKSPACE} that works to

I inserted Sleep() to slow down the execution of my script, in the hope it was a communication-exchange problem between FileZilla and FTP-server

I even thought about starting with filling in the c:\path, and then entering all the parameters for connection instances 5, 1, 2, 3, 4 and instance 6 after connection established. That silly script still refused to run properly, because he returns an error that the source or destination path isn't available !

That's why I started with the mouse position, and click on each position, point by point, but I know it's not the most reliable way to do.

So right now I am looking for different approach, and fresh ideas.

As soon as I have some brilliant idea, that work fine, I will post it right away.

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:1]", "serverid.com") ; OK

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:2]", "user") ; OK

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:3]", "password") ; OK

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:4]", "port") ; OK

Sleep( 500 )

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:5]", "{BACKSPACE}") ; OK

Sleep( 500 )

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:5]", "C:\path\files\www\")

Sleep( 500 )

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:6]", "{BACKSPACE}") ; OK

Sleep( 500 )

ControlSend("FileZilla", "", "[CLASS:Edit; INSTANCE:6]", "/www/Filename.txt")

Sleep( 500 )

MsgBox(64, "CONNECTION", "Welcome on the FTP-server !")

ControlClick("FileZilla", "", "[iD:122]") ; connection OK

Sleep( 1000 )

WinWaitActive("CurrentServerWindow") ; OK

Share this post


Link to post
Share on other sites
MikeP

well.. since I'm not busy I kept on searching.. all you need to simulate the right-clic is this :

Send("{APPSKEY}")

and yes, (since I've done such automation a bunch of times) you need to manage the time.. according to your system / internet performances with well placed and setup Sleep().

Edited by MikeP

Share this post


Link to post
Share on other sites
DirkVDB

well.. since I'm not busy I kept on searching.. all you need to simulate the right-clic is this :

Send("{APPSKEY}")

and yes, (since I've done such automation a bunch of times) you need to manage the time.. according to your system / internet performances with well placed and setup Sleep().

It was effectivly due to the incorrect use of 'Sleep()', since I adjusted the timing, by try line by line of code, the program is running perfectly.

I tried (again) to modifying the order of connection, this caused some unexpected problems.

The only thing I changed is establishing the connection first, then loading the file folders path.

Also I put the files in a separate folder on the FTP-server, now I just download the whole folder, wich allows me to reduce the number of mouse-clicks, and possible errors. Therefore I added some nice 'snippet' :

While WinActive ( "Target File Exists Already." ) ; build in warning

Sleep( 1000 ) ; must add Sleep() here otherwise it might be that the command is executed outside the window !

ControlClick("Target File Exists Already.", "", "[iD:5100]")

Sleep( 1000 ) ; also added Sleep() here because other similar windows might pop-up

WEnd

In other terms thanks to all of you, the program runs perfectly, special thanks to Squirrely and Mike.

Some hint for other programmers looking how to enter the source or file path,

I split up the path by resending it in several parts (including Sleep() each time), each Send() just appends to the previous one,

this allows the program to acces the path, folder by folder.... (otherwise it might happen that the program returns folder not found)

Sleep( 500 )

ControlSend("CurrentWindow", "", "[CLASS:Edit; INSTANCE:6]", "www/") ; for file path must use \ instead /

Sleep( 500 ) ; now the FTP-server has the time to locate the folders one by one

ControlSend("CurrentWindow", "", "[CLASS:Edit; INSTANCE:6]", "Folder1/")

Sleep( 500 )

ControlSend("CurrentWindow", "", "[CLASS:Edit; INSTANCE:6]", "Folder2/")

Edited by DirkVDB

Share this post


Link to post
Share on other sites
DirkVDB

I was a liitle to fast...

I encountered another problem, with the current use of mouseclicks it might happen that the filetree expands in a different way,

in such case all kind of files or folders are moved, wich is undesired action. (and making it difficult to trace what was moved where)

So I should be able to add a kind of 'filepath confirmation' on mouseclick action,

this function seems unavailable, I also checked on the German site

http://www.german-autoit.de/content/view/136/179/

but no function seems to exist for this issue, can anyone help on this ?

Or is there any command to get fixed filepath in a treeview ? Because with AutoIT Window Info when clicking on each different folder

it appears that they have alle same coordinates, mouse and window info

Anyway I have maybe found a solution to get arround this problem but I don't know yet if this could be reliable or not

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  

×