Results 1 to 10 of 10

Thread: Ftp get

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16

    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
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160
    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/
    Home Desktop : Windows 7 - 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 : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160
    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..
    Home Desktop : Windows 7 - 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 : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160
    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.

    Home Desktop : Windows 7 - 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 : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  7. #7
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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
    57
    Posts
    8,817
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    Junior Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    16
    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
    57
    Posts
    8,817
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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