Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 10 of 10

Thread: Ftp get

  1. #1

    Ftp get

    Hi,

    I didn't see any FTP forum so I hope it is ok to post to the INET forum (closest one in type).

    I was modifying your FTP sample.
    I was able to connect to my IP address and login.
    Able to change to my local directory, C:\
    Able to change my server/remote directory, /tmp

    Then normal in DOS, I would use GET filename newfilename (ex: GET TBT TBT.txt) and it would get the file and put it in my C: drive.

    So I copied the sample and used ftpresult = FTP_GetFile(TBT, "Async")

    But I didn't see any TBT file in my C: drive. Do I do something wrong?

    Second question: is there a way to rename the "get" file to add the .txt extension?

    Last question: I was thinking of having the user input their id and password. Right now it is hardcoded in the script. Is there a way to suppress the display of the password when they type it in via the CONSOLE module?

    Thanks. This is probably basic (no pun intended ) to you guys.

    PS: I was displaying the FTP GETFILE and it is 0. And displaying for the FTP FINISHED and it was 910.
    Last edited by TheOne; 09-04-2011 at 01:21.

  2. #2
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149
    It might be easier if you posted the code, just remove your login details and replace them.

    Here is site and file you could use

    ftp://ftp.bbc.co.uk/bin/tcf.gif

    or for a list visit

    http://www.ftp-sites.org/
    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  3. #3
    Hi Michael,

    This was taken mostly from the sample in the FTP folder. Just slightly modified.


    Uses "FTP" 'Script uses FTP module
    Uses "Console"

    '-------------------------------------------------------------------------
    'Variable declaration
    '-------------------------------------------------------------------------
    DIM ftpResult AS number
    DIM ftpConnect AS number
    Dim LocalDir As String
    DIM LocalDirList AS STRING
    DIM ServerDir AS STRING
    DIM ServerDirList AS STRING
    Dim FileName As String
    Dim FtpServer As String Value "x"
    Dim FtpUser As String Value "x"
    Dim FtpPass As String Value "x"
    Dim fBytesIn As Number



    '-------------------------------------------------------------------------
    'Start FTP connection
    '-------------------------------------------------------------------------

    '---Set a Log file so we can check later
    '---LOG file name has the same name of source file plus log ext
    ftpResult = FTP_SetLogFile(APP_SOURCENAME + ".Log")
    IF ftpResult < 0 THEN
    Console_Write("failed to set up log file")
    ELSE
    Console_Write("Logfile set up ok" + $CRLF)
    END IF

    '---Now try to connect to FTP site
    ftpConnect = FTP_Connect(FtpServer, FtpUser, FtpPass)
    IF ftpConnect < 0 THEN
    Stop
    END IF

    '---Set local directory
    LocalDir = "C:\"
    ftpResult = FTP_SetLocalDir(LocalDir)
    IF ftpResult >= 0 THEN
    Console_Write("C: directory is local directory" + $CRLF)
    ELSE
    Console_Write("Error setting to C: directory" + $CRLF)
    END IF

    '---Set directory on the server
    ServerDir = "/tmp"
    ftpResult = FTP_SetServerDir(ServerDir)
    IF ftpResult >= 0 THEN
    Console_Write("Directory /tmp found" + $CRLF)
    ELSE
    Console_Write("Directory /tmp is not found" + $CRLF)
    END IF


    '
    ' '-------------------------------------------------------------------------
    ' 'Start DownLoad process
    ' '-------------------------------------------------------------------------

    FileName = "TBT"
    ftpResult = FTP_GetFile("TBT","ASYNC")
    Console_Write("Get result code is: " + ftpResult + $CRLF)
    ftpResult = FTP_Finished
    Console_Write("FTP finished is: " + ftpResult + $CRLF)

    '-------------------------------------------------------------------------
    'Close FTP Connection
    '-------------------------------------------------------------------------
    IF ftpConnect >= 0 THEN
    ftpResult = FTP_Quit
    EndIf

    WaitKey

  4. #4
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149
    I made some bits more generic and add a loop for the download.

    It looks like FTP_FINISHED is a byte counter for the number of bytes left to download.


    Uses "FTP" 'Script uses FTP module
    Uses "Console"
    
    '-------------------------------------------------------------------------
    'Variable declaration
    '-------------------------------------------------------------------------
    Dim ftpResult     As Number
    Dim ftpConnect    As Number
    Dim LocalDir      As String
    Dim LocalDirList  As String
    Dim ServerDir     As String
    Dim ServerDirList As String
    Dim FileName      As String
    Dim FtpServer     As String Value "x"
    Dim FtpUser       As String Value "x"
    Dim FtpPass       As String Value "x"
    Dim fBytesIn      As Number
    
    
    '-------------------------------------------------------------------------
    'Start FTP connection
    '-------------------------------------------------------------------------
    
    '---Set a Log file so we can check later
    '---LOG file name has the same name of source file plus log ext
      ftpResult = FTP_SetLogFile(APP_SourceName + ".Log")
      If ftpResult < 0 Then
        Console_Write("failed to set up log file")
      Else
        Console_Write("Logfile set up ok" + $CRLF)
      End If
    
    '---Now try to connect to FTP site
      ftpConnect = FTP_Connect(FtpServer, FtpUser, FtpPass)
      If ftpConnect < 0 Then
        MsgBox 0, "Login Error - Check username / Password"
        Stop
      End If
    
    '---Set local directory
      LocalDir = "C:\"
      ftpResult = FTP_SetLocalDir(LocalDir)
      If ftpResult >= 0 Then
        Console_Write("C: directory is local directory" + $CRLF)
      Else
        Console_Write("Error setting to C: directory" + $CRLF)
      End If
    
    '---Set directory on the server
      ServerDir = "/tmp"
      ftpResult = FTP_SetServerDir(ServerDir)
      If ftpResult >= 0 Then
        Console_Write("Directory " + Chr$(34) + ServerDir + Chr$(34) +" found" + $CRLF)
      Else
        Console_Write("Directory " + Chr$(34) + ServerDir + Chr$(34) +" not found" + $CRLF)
      End If
    '
    ' '-------------------------------------------------------------------------
    ' 'Start DownLoad process
    ' '-------------------------------------------------------------------------
    
      FileName = "TBT"
      ftpResult = FTP_GetFile(FileName,"SYNC")
      Console_Write("Get result code is: " + ftpResult + $CRLF)
      Do
        DoEvents
      Loop Until FTP_Finished = 0   ' Loop until end of file reached
      
      ftpResult = FTP_Finished
      Console_Write("FTP finished is: " + ftpResult + $CRLF)
    
    '-------------------------------------------------------------------------
    'Close FTP Connection
    '-------------------------------------------------------------------------
      If ftpConnect >= 0 Then
        ftpResult = FTP_Quit
      EndIf
    
      WaitKey
    
    ps. Eros, If you get five minutes could you add a little bit of detail to some of the commands...please..
    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  5. #5
    Eureka! Thanks Michael.

    I didn't realize you needed a DO LOOP for the file to finish "downloading". Originally I copied the WHILE loop from the example. And it downloaded ok. But tried again later and it didn't. Thanks for the explanation about the FTP_FINISHED.

    Is there a way to have the file named as a .txt when it is downloaded?

    Also, can thinBasic suppress input/typing?

    Thank for all your help and knowledge!

  6. #6
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149
    I would rename the file after downloading, a user wouldn't see this operation.

    USES "FILE"

    n = FILE_Rename(Old_FileName, New_FileName)

    as for suppressing input I think Charles looked at this a while back but I cant remember what the result was ??? Simple answer I dont know but if anything comes to mind I will let you know.


    Mike C.

    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  7. #7
    Thanks Michael.

    I didn't even think to look at the File help manual section. I was concentrating on the FTP help manual section.

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,610
    Blog Entries
    2
    Rep Power
    10
    Quote Originally Posted by TheOne View Post
    Thanks Michael.

    I didn't even think to look at the File help manual section. I was concentrating on the FTP help manual section.
    Well, I'm very sorry I didn't finish FTP_... manual reference.
    I will do it for the next update.

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  9. #9
    Hi Eros,

    You have done a fantastic job with the help manual.

    Anything not there, I guess that's what the forum is for.

    Believe me, without you guys, I would be stuck and banging my poor head on the walls.

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,610
    Blog Entries
    2
    Rep Power
    10
    I've just published thinBasic beta 1.8.7

    It has a new complete help for FTP keywords. I've also rewritten almost entirely FTP module and now it has no dependency external dlls.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •