Jump to content
Sign in to follow this  
COD3369

check file exsist on server

Recommended Posts

COD3369

am making a automation script that regularly checks a specific folder for changes.. but I want to know that how we use can we check that file exsist on server or not. if exsist then download the file from server..

thank you

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum,

is this a fileserver on an internal network or a server you access using TCP/IP (internet).

It then depends on the services the server provides (FTP, HTTP).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
COD3369

@water first of all thank you for quick reply , yes its ftp need to check using ftp.

Share this post


Link to post
Share on other sites
water

Please check the FTP UDF in the help file, section User Defined Functions -> FTPEx.

To check a file for existance you could use _FTP_FileGetSize. Doesn't put too much overhead on the server and the script and returns an error if the file doesn't exist.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
COD3369

can you please provide me a liitle code for it please I am newbie to autoit.. :(

Share this post


Link to post
Share on other sites
water

Global $server = "servername or IP.address.of.your.server"
Global $username = "usernmae"
Global $pass = "password"
Global $Open = _FTP_Open('MyFTP Control')
Global $Conn = _FTP_Connect($Open, $server, $username, $pass)
Global $FileSize = _FTP_FileGetSize($Conn, "your filename")
Global $Ftpc = _FTP_Close($Open)
Error checking has to be added by you ;) Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
COD3369

thank you very much for this bro :)

Share this post


Link to post
Share on other sites
water

Hope it works.

Just did a q&d copy from the help file.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Mechaflash

You're not getting a refund on that fish water =P


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites
water

It's a start, so just half of a fish ;)

The OP still has to check the result of _FTP_FileGetSize and code the rest of the script. Error checking is also missing.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
VelvetElvis

Global $server = "servername or IP.address.of.your.server"
Global $username = "usernmae"
Global $pass = "password"
Global $Open = _FTP_Open('MyFTP Control')
Global $Conn = _FTP_Connect($Open, $server, $username, $pass)
Global $FileSize = _FTP_FileGetSize($Conn, "your filename")
Global $Ftpc = _FTP_Close($Open)
Error checking has to be added by you ;)

Looking for something like this myself. Changed this a wee bit to add a simple msgbox

#include
Global $server = "myserver"
Global $username = "myusername"
Global $pass = "mypassword"
Global $Open = _FTP_Open('MyFTP Control')
Global $Conn = _FTP_Connect($Open, $server, $username, $pass)
Global $FileSize = _FTP_FileGetSize($Conn, "irreg.txt")
;Global $FileSize = _FTP_FileGetSize($Conn, "session.asp")
If @error Then
MsgBox(0, "", "Error: " & @error)
Else
MsgBox(0, "", $FileSize)
EndIf
Global $Ftpc = _FTP_Close($Open)

Works great, except for zero-length files. I get the same error (-1) that I get for a non-existent file.

Does anyone know an easy workaround?

Share this post


Link to post
Share on other sites
water

If you get -1 you could try to read the file using

$result = _FTP_FileRead($hFile, 1)
I assume you get @error = -1 (End of file) and $result is set to "".

If the file doesn't exist you should get another value for @error.

Could you give this a try?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
VelvetElvis

If you get -1 you could try to read the file using

$result = _FTP_FileRead($hFile, 1)
I assume you get @error = -1 (End of file) and $result is set to "".

If the file doesn't exist you should get another value for @error.

Could you give this a try?

OK using this code:

$handle = _FTP_FileOpen($Conn, $filename)
$result = _FTP_FileRead($handle, 1)
MsgBox(0, "", "Error: " & @error & " Result: " & $result)

- Empty file: Error -1 Result 0

- 80k text file: Error 0 Result 0x30

- Non-existant file: Error 2 Result 0

So it looks like if there's an empty file in the mix, I'm thinking it's probably better to forget this and read all the filenames via _FTP_ListToArray() and check for them there.

Share this post


Link to post
Share on other sites
COD3369

thank you guys:D

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×