Jump to content

FileOpen from FTP Server?


Recommended Posts

Hi Guys!

First time poster, long time AutoIT user! Just wondering if there is an easy way to open a file from an FTP Server. I have a bunch of log files on an FTP and need to open each and do some parsing. Any help would be appreciated!

Thanks!

Link to comment
Share on other sites

Alright, so here is what I've come up with so far...

#include <FTPEx.au3>

$server = 'ftp.address.com'
$username = 'username'
$pass = 'pass'

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, $username, $pass)

Local $h_Handle
$aFile = _FTP_FindFileFirst($Conn, "/status", $h_Handle)

for $i = 1 To $aFile[1]+1 Step 1
    ConsoleWrite('$Filename = ' & $aFile[10] & ' -> Error code: ' & @error & @crlf)
    $aFile = _FTP_FindFileNext($h_Handle)
Next

$FindClose = _FTP_FindFileClose($h_Handle)
$Ftpc = _FTP_Close($Open)

This is successfully getting the filenames from the directory. Now I need to open the file and parse it for specific words. Any pointers on where to start? Probably _FTP_FileOpen and _FTP_FileRead? Any examples on how to implement this?

Thanks!

Link to comment
Share on other sites

  • 2 months later...

Here is how to open txt file and read from it.

#Include <FTPEx.au3>

$s_ServerName ='12.12.12.8'
$s_Username = 'user'
$s_Password = 'pass'
$lpszFileName='something.txt'
$s_Remote = '/working dir name /'
$Open = _FTP_Open('MyFTP Control')
$hConnect = _FTP_Connect($Open, $s_ServerName, $s_Username, $s_Password)
_FTP_DirSetCurrent($hConnect, $s_Remote)
$dwNumberOfBytesToRead = _FTP_FileGetSize($hConnect, $lpszFileName)
$h_File = _FTP_FileOpen($hConnect, $lpszFileName)
msgbox(0,"",BinaryToString (_FTP_FileRead($h_File, $dwNumberOfBytesToRead)))
$Ftpc = _FTP_Close($Open)
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...