|
-
Nov 29th, 2005, 07:51 PM
#1
Thread Starter
Addicted Member
[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..
-
Nov 29th, 2005, 07:58 PM
#2
Re: Inet FTP query
I don't think setting Document is necessary...
-
Nov 29th, 2005, 08:00 PM
#3
Thread Starter
Addicted Member
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
-
Nov 29th, 2005, 08:03 PM
#4
Re: Inet FTP query
It hangs on which line? Step through to make sure. Also, you m,ight need to use URL instead of RemoteHost. UserName/Pwd might be case sensitive as well...
-
Nov 29th, 2005, 08:10 PM
#5
Thread Starter
Addicted Member
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
-
Nov 29th, 2005, 08:12 PM
#6
Re: Inet FTP query
Hmmm, how do you disconnect from FTP site (if at all)?
You should have something like the following when you click the EXIT button or during form_unload event (at least):
-
Nov 29th, 2005, 08:50 PM
#7
Thread Starter
Addicted Member
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?
-
Nov 29th, 2005, 09:07 PM
#8
Re: Inet FTP query
It's Inet1.Execute , "DELETE ..." but user must have necessary permissions, though.
-
Nov 29th, 2005, 10:16 PM
#9
Thread Starter
Addicted Member
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...
-
Nov 29th, 2005, 10:22 PM
#10
Re: Inet FTP query
Try the Sleep() API.
VB Code:
Option Explicit
'This project needs a button
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Me.Caption = "Your system will sleep 5 sec."
'Sleep for 5000 milliseconds
Sleep 5000
Beep
Me.Caption = ""
End Sub
Private Sub Form_Load()
Me.Caption = ""
Command1.Caption = "Sleep ..."
End Sub
-
Nov 29th, 2005, 10:34 PM
#11
Thread Starter
Addicted Member
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?
-
Nov 29th, 2005, 10:43 PM
#12
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
-
Nov 29th, 2005, 10:46 PM
#13
Thread Starter
Addicted Member
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.
-
Nov 29th, 2005, 10:53 PM
#14
Re: Inet FTP query
Can you try this? Maybe it needs / instead of \ though?
VB Code:
FTPInet.Execute , "Put C:\Test.txt \ANewDirectory\Test.txt"
-
Nov 29th, 2005, 11:03 PM
#15
Thread Starter
Addicted Member
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.
-
Nov 29th, 2005, 11:17 PM
#16
Re: Inet FTP query
That is kind of strange. Glad you have it working though.
-
Nov 29th, 2005, 11:21 PM
#17
Thread Starter
Addicted Member
Re: Inet FTP query
Yeah, thanks for that
-
Nov 29th, 2005, 11:31 PM
#18
Thread Starter
Addicted Member
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"
-
Nov 30th, 2005, 12:00 AM
#19
Re: Inet FTP query
Cool. How long does that take?
-
Nov 30th, 2005, 12:05 AM
#20
Thread Starter
Addicted Member
Re: Inet FTP query
*sticks in a couple of lable text changes to guestimate the total amount of time*
2-3 seconds ^_^
-
Nov 30th, 2005, 02:38 PM
#21
Thread Starter
Addicted Member
Re: Inet FTP query
Another quick query:
What's the correct command syntax for:
FTPInet.Execute , MkDir("2")
IOW, to make a directory?
-
Nov 30th, 2005, 03:52 PM
#22
Re: Inet FTP query
Just like any other command it has to be part of string:
FTPInet.Execute , "MKDIR ..."
-
Nov 30th, 2005, 04:26 PM
#23
Thread Starter
Addicted Member
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 ^^
-
Nov 30th, 2005, 05:33 PM
#24
Re: Inet FTP query
Glad you've sorted it.
-
Dec 1st, 2005, 03:49 PM
#25
Thread Starter
Addicted Member
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
-
Dec 1st, 2005, 03:57 PM
#26
Re: Inet FTP query
Can't you use an error routine to trap the error?
-
Dec 2nd, 2005, 01:10 AM
#27
Thread Starter
Addicted Member
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.
-
Dec 2nd, 2005, 01:47 AM
#28
Re: Inet FTP query
Here is a simple example. You can add to it:
VB Code:
Private Sub Form_Load()
On Error GoTo error_found
' download a file
On Error GoTo 0 ' turn off error trap
Exit Sub
error_found:
On Error GoTo 0
MsgBox "Error!"
Resume Next
End Sub
-
Dec 2nd, 2005, 01:59 AM
#29
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|