Results 1 to 29 of 29

Thread: [RESOLVED] Inet FTP query

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved [RESOLVED] Inet FTP query

    Hi all,

    I've been trying to add FTP to a program that I'm making using the Inet thingy.. I've read through all of the FTP related threads on this subforum that i can find and read some MSDN articles, but it's all pretty tricky stuff. Can someone explain Inet commands basically to me? I can't find anything on Google..
    Also, I have this sample code:

    Code:
    Private Sub uwt_click()
    
    FTPInet.RemoteHost = "My.server"
    FTPInet.RemotePort = "21"
    FTPInet.UserName = "Username"
    FTPInet.Password = "Password"
    FTPInet.Document = "C:\Test.txt"
    FTPInet.Execute , "Put C:\Test.txt Test.txt"
    
    End Sub
    Is that correct? It seems to just hang my program each time..

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    I tried it again without setting document, it still doesn't work and still causes VB to hang for like 2 minutes

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    I tried with URL, still doesn't work sadly I've got the username/pass correct case-wise, too.

    It doesn't actually hang on the code, but when i click the exit button or the "stop" button to stop the code in VB, nothing happens for like 2 mins, and then it finally stops the code

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Ohh, it does appear to be working. It's just that my FTP server is screwing up (again T_T)

    BTW, what's the command for deleting a file?

  8. #8

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Oh, another little problem:

    Code:
    FTPInet.RemoteHost = "FTP_addy"
    FTPInet.UserName = "UserName"
    FTPInet.Password = "Pass"
    FTPInet.Execute , "CD ANewDirectory"
    FTPInet.Execute , "Put C:\Test.txt Test.txt"
    If I do this (navigate to a different folder, and then try to use "put"), it tells me that it's still executing the last command (CD) when it tries to go onto the next one (Put). Is there any way i can put a "puase" or "wait" kind thing in there? I tried using a timer and a "while", but I couldn't get it to work...

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    Try the Sleep() API.
    VB Code:
    1. Option Explicit
    2. 'This project needs a button
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Sub Command1_Click()
    6.     'KPD-Team 1998
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Me.Caption = "Your system will sleep 5 sec."
    10.     'Sleep for 5000 milliseconds
    11.     Sleep 5000
    12.     Beep
    13.     Me.Caption = ""
    14. End Sub
    15.  
    16. Private Sub Form_Load()
    17.     Me.Caption = ""
    18.     Command1.Caption = "Sleep ..."
    19. End Sub

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Ah, the sleep seems to work great, thank you
    However, even with a sleep as long as 30 seconds, i'm still getting the "Run-time error 35764: still executing last request" error. Is that normal? anything I'm missing in my code?

    I know the login details are correct, because if I put the first 4 lines in form_load, the form takes about a second to load and then the file transfers fine?
    Update: I just moved the "Close" (disconnect from FTP) command to the button, instead of the form exit button, and i'm getting the same error. Is it just not possible to perform several operations with one button, or something?

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    What OS are you uploading to? Perhaps you need a vbCrLf or vbNewLine at the end of the CD line?

    30 seconds = 30000 ms

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Hmm, I don't know the server exactly.. My home server has given up on me so I'm just using my free ISP hosting (ntlworld).. I can send you the login details if you like?

    It's probably linux based or something though, they like to keep the costs down of these big ISP free hosting servers..


    EDIT: Tried adding "vbNewLine" to the end of the "FTPInet.Execute , "CD NewDir"" line, and it gave an error that it didn't expect anything else after than instruction. Also tried putting it next to NewDir, within the quotes, but it just uploaded to the / directory


    EDIT2: Also tried this format:
    FTPInet.Execute , "CD NewDir", vbNewLine
    It still gives the "Still executing last command" error
    Last edited by BubbleLife; Nov 29th, 2005 at 10:52 PM.

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    Can you try this? Maybe it needs / instead of \ though?

    VB Code:
    1. FTPInet.Execute , "Put C:\Test.txt \ANewDirectory\Test.txt"

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    FTPInet.RemoteHost = "Host"
    FTPInet.UserName = "User"
    FTPInet.Password = "Pass"
    FTPInet.Execute , "Put C:\Test.txt NewDir/Woot.txt"

    That worked ^_^ Thank you
    Although, sadly I still can't put the "close" line in the same sub, still causes it to crash ^^;

    I wonder what will happen if i try, eventually for the full program to deal with several files :S


    EDIT:
    Just added a second line under
    FTPInet.Execute , "Put C:\Test.txt NewDir/Woot.txt"
    With Woot2. It crashes T_T

    It's surely not meant to take that long to execute a command, is it?

    EDIT2:
    Interesting. I can put a sleep delay in for any amount of time, i've tried right up to 1min, but it still comes back with the "still executing command" error. However, if i put a msgbox between the two file uploads, they both work, even if i click the box straight away....

    EDIT3:

    I'm not sure of it's usage, but there's apparently a command
    FTPInet.StillExecuting
    Maybe that could somehow tell the system to not try and execute the next line of code until it's finished, or something?
    Last edited by BubbleLife; Nov 29th, 2005 at 11:18 PM.

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    That is kind of strange. Glad you have it working though.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Yeah, thanks for that

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Fixed it!

    FTPInet.Execute , "Put C:\Test.txt NewDir/Test.txt"
    Do While FTPInet.StillExecuting
    DoEvents
    Loop
    FTPInet.Execute , "Put C:\Test2.txt NewDir/Test2.txt"

  19. #19
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    Cool. How long does that take?

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    *sticks in a couple of lable text changes to guestimate the total amount of time*
    2-3 seconds ^_^

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Another quick query:

    What's the correct command syntax for:

    FTPInet.Execute , MkDir("2")

    IOW, to make a directory?

  22. #22

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Ah, found it. That wasn't the problem; I tried it lots of ways, but I was putting "MKDIR 2" rather than "MKDIR NewDir\2", and i wasn't refreshing the root directory ^^

  24. #24

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Sorry, another quick question ^^;; (Ever wonder why i haven't marked it as "resolved" yet? )

    Is there any way to see if a file exists on a server via Inet FTP?
    For example, to check if a file exists on a system before opining/trying to work with it (because, if it wasn't there, the program would crash):

    Code:
    Dim CheckFile as string
    CheckFile = Dir$("C:\test.txt")
    If CheckFile = "test.exe" then
       DoStuff
    Else
       Msgbox "File does not exist"
    end if
    Or something. I've been working with FTP recently (using the Inet thingy) and on one occasion, it needs to connect to a server to download a file. However, if the file isn't there, it crashes, giving me some kind of memory stack error.

    So, is there an FTP command to check if a file exists, so that I can basically say:

    <Command to check file exists>
    If <Command to check file exists> result = yes then
    Dostuff

    etc?

    Thanks

  26. #26
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    Can't you use an error routine to trap the error?

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    What's one of those? Or, how do I do that?

    The thing is, I don't want the code to stop executing. I.e. if it can't find the file and gives an error, i'd like it to just go onto the next line.

  28. #28
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Inet FTP query

    Here is a simple example. You can add to it:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.   On Error GoTo error_found
    4.     ' download a file
    5.   On Error GoTo 0 ' turn off error trap
    6.   Exit Sub
    7.  
    8. error_found:
    9.   On Error GoTo 0
    10.   MsgBox "Error!"
    11.   Resume Next
    12.  
    13. End Sub

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Inet FTP query

    Ah! That's great, thank you

    If you don't mind me asking, what does GoTo 0 mean?

    Also, my program is now complete ^_^ I can post it here, if that's allowed?

Posting Permissions

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



Click Here to Expand Forum to Full Width