Sign in to follow this  
Followers 0
kaotkbliss

append txt file on ftp

8 posts in this topic

#1 ·  Posted (edited)

I'm trying to add a new entry to a text file on an ftp server via autoit.

I don't want a file to be created on the pc itself as I'm trying to minimize the possibility of users manually editing the file before it's being sent back to the ftp.

What my program will do is read the contents of the list to an array, search the array against a registry entry and if there is no match will have the user enter info into input boxes.

I then want the program to take the entered information and add it to the text file on the ftp.

#include <FTPEx.au3>
$server = "ftp.site"
$username = 'username'
$pass = 'pass'
$filename = "list.txt"
$Open = _FTP_Open('MyFTP')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
$Users = _FTP_FileOpen($Conn,$filename)
FileWriteLine($Users,"test-test"&@CRLF)
_FTP_FileClose($Users)
_FTP_Close($Open)

*edit* I should mention that everything else is working, just need to add to the text

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites



Would this even be possible? Perhaps I need a new ftp server (Currently I'm using Serversfree.com and maybe it just doesn't support something like this?)


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

I don't think you can "direct edit" on an ftp server. This might work:

open --> edit --> put (overwrite mode)

Not tested .. but, something like that.


"Today's scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality." ~ Nikola Tesla

Share this post


Link to post
Share on other sites

So basically, I'd have to create an obscure "temp" file -> make the edit -> upload the file -> delete the local temp file?


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I haven't done very much research on FTPEx.au3.

Just glancing at it... looks to me something maybe...

$Users = _FTP_FileOpen($Conn,$filename)

$sRead = _FTP_FileRead($Users)

_FTP_FileClose($Users)

You have the file in $sRead, from there you can do what you need with AutoIt internals

and then save the file with same name and_FTPPutFile() ... then delete file on PC.

I don't think there's another way around it, since most FTP programs do the same thing.

---

I just saw this: _FTPReadFile(). Might be quicker than opening and closing.

--edit : correction at $sRead line

Edited by ripdad

"Today's scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality." ~ Nikola Tesla

Share this post


Link to post
Share on other sites

hmmm. I do not see an _FTPReadFile

What I've done and have working successfully, is reading the ftp file to an array

$Open = _FTP_Open('MyFTP')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
$Users = _FTP_FileOpen($Conn,$filename)
$Size = _FTP_FileGetSize($Conn,$filename)
If $Size = 0 Then $Size = 1000
$Read = _FTP_FileRead($Users,$Size)
$fromhex = _HexToString($Read)
$list = StringSplit($fromhex,@CRLF)

then I loop through the array and check the registry for a match.

if no match then the user enters their info into an input box which is then added to the end of the array with _ArrayAdd()

so far nothing is saved on the local drive but since I can't write directly to the ftp I'll have to write the array to a file, upload that file to replace the old, then delete the file from the local pc.

Well, I was going to have to look into encryption soon anyway for the ftp username and pass...


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

oops, was looking at old functions by mistake, sorry.

maybe some manipulation - I suppose you could save as random obscure temp file, after edit upload it, delete "list.txt" on server, rename obscure uploaded temp file to "list.txt", then delete obscure temp file on PC or FileOpen($sFile, 2) and FileClose($sFile) on it, then delete.

anyways, good luck to you.

Edited by ripdad

"Today's scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality." ~ Nikola Tesla

Share this post


Link to post
Share on other sites

hmm, I kinda like the FileOpen($sFile, 2) before deleting. That way, if they manage to recover the deleted file, it should be blank anyway. Maybe write some nonsense or a poem to it before deleting lol


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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