| 1. |
Solve : FTP and displaying a file? |
|
Answer» Hey guys! I need a script that can write to (and read from) a file on a ftp host. The ftp command in Command doesn't help at all. I tried doing "help ftp", doesn't work..."ftp /?" just says unknown host... The ftp command in Command doesn't help at all. I tried doing "help ftp", doesn't work..."ftp /?" just says unknown host... FTP is an environment. From command line type FTP, when the FTP> prompt appears, type help. Read is the get command, write is the put command. Quote I'm trying to get it to only display 22 lines (which works fine) and also auto-update every second. The latter doesn't work...For some reason, if a file contains less than 22 lines, then it will just repeat the lines untill there are 22 in display...and if there are 22 or more, it doesn't auto update... Explain auto-update. How is the testfilelines.txt file getting updated? From what I can see, the code counts the records in the file and displays the last 22. If less than 23 records exist, all the records are displayed. The file updates often (possibly less than a second per update), so I need to show the changes. But how do I actually USE the FTP command to read and write to files?This simplified version of the code may help: Code: [Select]@echo off setlocal :loop echo ----- set dx=0 set fname=testfilelines.txt for /f "tokens=* delims=" %%x in (%fname%) do ( call set /a dx=%%dx%%+1 ) set /a last=%dx%-22 if %last% LSS 0 ( for /f "tokens=* delims=" %%x in (%fname%) do echo %%x ) else ( for /f "skip=%last% tokens=* delims=" %%x in (%fname%) do echo %%x ) echo ----- ping localhost -n 2 -w 1000 > nul cls goto loop Concerning the other question, click in the left hand panel for the correct syntax of the FTP commands.Quote from: Sidewinder on February 04, 2009, 06:28:36 PM This simplified version of the code may help:Let's assume the following: my username is: fakename And my password is: notreal And my ftp server is: ftp.fakesite.com It doesn't say anything about AUTOMATICALLY LOGGING in to a FTP server and writing/reading a file.I always thought that forums are a vehicle for sharing information. I thought after you learned FTP, you would come back here and SHARE with us. That FTP link was to give you all the tools you would need to write your own script. A little research on the FTP command line and you should have been good to go. Code: [Select]ftp -s:myScript.txt ftp.fakesite.com myScript.txt Code: [Select]fakename notreal cd /files put file.zip bye The above script uploads file.zip to the files directory on the remote site. To answer the question not asked. I would not try to combine the ftp into the other script. Instead try running both simultaneously in different windows. Quote from: Sidewinder on February 05, 2009, 05:00:01 AM I always thought that forums are a vehicle for sharing information. I thought after you learned FTP, you would come back here and share with us.Is it possible to append a line of text to the end of say file.txt using FTP?Quote Is it possible to append a line of text to the end of say file.txt using FTP? Apparently. This very topic is discussed on the very FIRST page of the FTP link I gave you. If you need help with specific commands, enter ? command at the FTP> prompt. Unless you get very lucky, it's rare that your research will spell out exactly what you're looking for. More likely you can learn by example or gain enough knowledge to be able to proceed. any way to read out the contents of a file too?Code: [Select]open you.yourdomain.com username password get file.txt bye then in file.bat Code: [Select]@echo off type file.txt pause >nul That's sort of what I was thinking...Quote from: Sidewinder on February 05, 2009, 05:00:01 AM I always thought that forums are a vehicle for sharing information. I thought after you learned FTP, you would come back here and share with us.Sorry this is an old thread...but I've run into another problem. How can I run multiple FTP commands in the script, as in not in a seperate file? |
|