I am new to FTP Concept . Last two days i have been searching on the internet about and got the following example
Code:
Dim ftp As FTPClass
Dim f As FTPFileClass
Set ftp = New FTPClass
If ftp.OpenFTP("ftp://ftp.<machine ip>", "root", "P@ssw0rd") Then
MsgBox "Connected"
If ftp.SetCurrentFolder("\temp\") Then
MsgBox "inside second if"
For Each f In ftp.Files
MsgBox "inside for block"
ftp.GetFile f.FileName, DownLoadFolder & "\" & f.FileName, True
Next
End If
ftp.CloseFTP
Else
MsgBox "Not Connected"
End If
Set ftp = Nothing
Instead of creating an ftp server, i am treating another machine as ftp server and i am passing that machine ip. When i am running the above code i am always getting the message "Not Connected" Please guide me where i am doing . I am enclosing class files also. Port number is 20.
I am new to FTP Concept . Last two days i have been searching on the internet about and got the following example
Code:
Dim ftp As FTPClass
Dim f As FTPFileClass
Set ftp = New FTPClass
If ftp.OpenFTP("ftp://ftp.<machine ip>", "root", "P@ssw0rd") Then
MsgBox "Connected"
If ftp.SetCurrentFolder("\temp\") Then
MsgBox "inside second if"
For Each f In ftp.Files
MsgBox "inside for block"
ftp.GetFile f.FileName, DownLoadFolder & "\" & f.FileName, True
Next
End If
ftp.CloseFTP
Else
MsgBox "Not Connected"
End If
Set ftp = Nothing
Instead of creating an ftp server, i am treating another machine as ftp server and i am passing that machine ip. When i am running the above code i am always getting the message "Not Connected" Please guide me where i am doing . I am enclosing class files also. Port number is 20.
Thanks in Advance
The other guy has been using FileZilla and operating system is linux. In linux ftpsever comes by default. We need to install or configure any ftp server on it. So i have treated his machine as ftp server and my machine as ftpclient. Now i want to connect to it. through code
When i am running the above code i am always getting the message "Not Connected"
we would have to assume that there is something wrong with your connection
If ftp.OpenFTP("ftp://ftp.<machine ip>", "root", "P@ssw0rd") Then
ip address, user or password
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim data As String
Dim data1 As String
Select Case State
Case icError
MsgBox Inet1.ResponseInfo, , "File failed to transfer"
Case icResolvingHost
Label6.Caption = "Resolving Host"
Case icHostResolved
Label6.Caption = "Host Resolved"
Case icConnecting
Label6.Caption = "Connecting Host"
Case icConnected
Label6.Caption = "Host connected"
Case icReceivingResponse
Label6.Caption = "Receiving Response"
Case icResponseReceived
Label6.Caption = "Got Response"
Case icResponseCompleted
MsgBox "Transfer Completed"
Do
data1 = Inet1.GetChunk(1024, icString)
data = data & data1
Loop While Len(data1) <> 0
Text6.Text = data
End Select
End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Last edited by jmsrickland; Sep 10th, 2012 at 01:08 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Then you are having a problem that lies outside of your code. I copied your code exactly as is from post 5 and of course I had same problem you did. When I added the comma it worked perfectly; It made the connection. Are you sure you are even connected to the internet? Maybe a firewall issue? Something else we don't know about?
Try below code. I copied it from Microsoft and it works perfectly
Code:
Private Sub Command1_Click()
Inet1.URL = "ftp://ftp.microsoft.com"
Inet1.UserName = "anonymous"
Inet1.Password = ""
Inet1.Execute , "DIR"
End Sub
Private Sub inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant ' Data variable.
Select Case State
' ... Other cases not shown.
Case icError ' 11
' In case of error, return ResponseCode and
' ResponseInfo.
vtData = Inet1.ResponseCode & ":" & _
Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim strData As String: strData = ""
Dim bDone As Boolean: bDone = False
' Get first chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
MsgBox strData
End Select
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Then you are having a problem that lies outside of your code. I copied your code exactly as is from post 5 and of course I had same problem you did. When I added the comma it worked perfectly; It made the connection. Are you sure you are even connected to the internet? Maybe a firewall issue? Something else we don't know about?
Try below code. I copied it from Microsoft and it works perfectly
Code:
Private Sub Command1_Click()
Inet1.URL = "ftp://ftp.microsoft.com"
Inet1.UserName = "anonymous"
Inet1.Password = ""
Inet1.Execute , "DIR"
End Sub
Private Sub inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant ' Data variable.
Select Case State
' ... Other cases not shown.
Case icError ' 11
' In case of error, return ResponseCode and
' ResponseInfo.
vtData = Inet1.ResponseCode & ":" & _
Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim strData As String: strData = ""
Dim bDone As Boolean: bDone = False
' Get first chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
MsgBox strData
End Select
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Then you are having a problem that lies outside of your code. I copied your code exactly as is from post 5 and of course I had same problem you did. When I added the comma it worked perfectly; It made the connection. Are you sure you are even connected to the internet? Maybe a firewall issue? Something else we don't know about?
Try below code. I copied it from Microsoft and it works perfectly
Code:
Private Sub Command1_Click()
Inet1.URL = "ftp://ftp.microsoft.com"
Inet1.UserName = "anonymous"
Inet1.Password = ""
Inet1.Execute , "DIR"
End Sub
Private Sub inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant ' Data variable.
Select Case State
' ... Other cases not shown.
Case icError ' 11
' In case of error, return ResponseCode and
' ResponseInfo.
vtData = Inet1.ResponseCode & ":" & _
Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim strData As String: strData = ""
Dim bDone As Boolean: bDone = False
' Get first chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
MsgBox strData
End Select
End Sub
Thanks for your reply.
I will work on this regard and will check my LAN Settings if any thing is getting blocked or firewall .