Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: FTP and displaying a file  (Read 7398 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
FTP and displaying a file
« on: February 04, 2009, 03:10:27 PM »
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...

Can anyone help?

Also, I've been having trouble with this little code I found a while back.
Code: [Select]
@echo off
setlocal
:loop
echo -----
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 (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
)
) else (
for /f "skip=%last% tokens=* delims=" %%x in (%fname%) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
))

for /l %%x in (1,1,%idx%) do call echo %%array.%%x%%
echo -----
ping localhost -n 2 -w 1000 > nul
cls
goto loop

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...

The type command is not what I'm looking for, as it is the main reason why I wanted this code. Type will display ALL the contents, I found that when it loops, it gets jumpy on refreshing.


If you can help with one or more problems, that would be great!
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: FTP and displaying a file
« Reply #1 on: February 04, 2009, 05:17:21 PM »
Quote
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.

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: FTP and displaying a file
« Reply #2 on: February 04, 2009, 05:33:18 PM »
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?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: FTP and displaying a file
« Reply #3 on: February 04, 2009, 06:28:36 PM »
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.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: FTP and displaying a file
« Reply #4 on: February 04, 2009, 06:56:12 PM »
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.
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.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: FTP and displaying a file
« Reply #5 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. ;)

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. <sigh>

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.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: FTP and displaying a file
« Reply #6 on: February 05, 2009, 02:31:29 PM »
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. <sigh>

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.

Is it possible to append a line of text to the end of say file.txt using FTP?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: FTP and displaying a file
« Reply #7 on: February 05, 2009, 03:09:41 PM »
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.

 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: FTP and displaying a file
« Reply #8 on: February 14, 2009, 05:38:59 PM »
any way to read out the contents of a file too?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Jacob



    Hopeful

    Thanked: 1
    • Experience: Expert
    • OS: Windows XP
    Re: FTP and displaying a file
    « Reply #9 on: February 15, 2009, 03:15:35 AM »
    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
    « Last Edit: February 15, 2009, 02:40:04 PM by Jacob »

    Helpmeh

      Topic Starter


      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: FTP and displaying a file
    « Reply #10 on: February 15, 2009, 12:24:27 PM »
    That's sort of what I was thinking...
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Helpmeh

      Topic Starter


      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: FTP and displaying a file
    « Reply #11 on: March 09, 2009, 03:06:25 PM »
    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. <sigh>

    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.

    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?
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.