Internet Transfer Control #2

  • Follow


Hi everybody,

I have this tiny problem which I am not able to solve.
I use an Internet Transfer Control to upload a file.
I use the following code which I found on vb-helper.

Private Function UploadFile(ByVal source_file As String, ByVal dest_file As 
String, ByVal host_name As String, ByVal user_name As String, ByVal passwd 
As String) As Boolean
    ' Get the file's contents.
    On Error GoTo UploadError

    ' You must set the URL before the user name and
    ' password. Otherwise the control cannot verify
    ' the user name and password and you get the error:
    '
    '       Unable to connect to remote host
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & 
host_name
    inetFtp.URL = host_name
    inetFtp.UserName = user_name
    inetFtp.Password = passwd

    ' Do not include the host name here. That will make
    ' the control try to use its default user name and
    ' password and you'll get the error again.
    Debug.Print "Put " & source_file & " " & dest_file
    inetFtp.Execute , "Put " & source_file & " " & dest_file

    UploadFile = True
    Exit Function

UploadError:
    MsgBox "Error " & Err.Number & _
        " uploading file '" & _
        source_file & "' to '" & _
        dest_file & "'." & vbCrLf & Err.Description, _
        vbExclamation Or vbOKOnly, _
        "Download Error"
    UploadFile = False
    Exit Function
End Function

The problem is that when I try to execute this code from the
computer in my work (directly connected to the Internet) the
code is executed without any problem.
When I try though to run the code from my home computer
the code doesn't execute (no file is uploaded).
From my home I connect to the Internet with a lan (computer
connected to a switch which is conected to the ADSL Rooter).
I am able to retrieve information with IntTransfContr from the
Internet but I cannot upload. Any suggestions? 


0
Reply someone1201 (5) 3/13/2008 3:58:06 PM

On Thu, 13 Mar 2008 17:58:06 +0200, "Pyrforos" <someone@mail.gr>
wrote:

>Hi everybody,
>
>I have this tiny problem which I am not able to solve.
>I use an Internet Transfer Control to upload a file.
>I use the following code which I found on vb-helper.
>
>Private Function UploadFile(ByVal source_file As String, ByVal dest_file As 
>String, ByVal host_name As String, ByVal user_name As String, ByVal passwd 
>As String) As Boolean
>    ' Get the file's contents.
>    On Error GoTo UploadError
>
>    ' You must set the URL before the user name and
>    ' password. Otherwise the control cannot verify
>    ' the user name and password and you get the error:
>    '
>    '       Unable to connect to remote host

I'd have to say it's in the line below, if not anywhere else too.
if host_name has a value like ;http://andahostname then 
  "host_name = "ftp://" & host_name"
will result in host_name  =ftp://http://...

>    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & 
>host_name

it should be:
  If LCase$(Left$(host_name, 6)) <> "ftp://" Then
     If InStr(host_name, "://", 1)  Then
       host_name = "ftp://" & _
          Mid(host_name, InStr(host_name, "://", 1) + 3)
     Else
       host_name = "ftp://" & host_name
     End If
  End If

Then, if that doesn't work, you need to check what the values are for
host_name, source_file and dest_file to see if perhaps it's something
like the fileseperator character "\" or "/".  Also, check that
user_name and passwd values are correct.

Try putting a Debug.Print here for host_name if you have to work on it
at work then try it at home.

>    inetFtp.URL = host_name
>    inetFtp.UserName = user_name
>    inetFtp.Password = passwd
>
>    ' Do not include the host name here. That will make
>    ' the control try to use its default user name and
>    ' password and you'll get the error again.
>    Debug.Print "Put " & source_file & " " & dest_file
>    inetFtp.Execute , "Put " & source_file & " " & dest_file
>
>    UploadFile = True
>    Exit Function
>
>UploadError:
>    MsgBox "Error " & Err.Number & _
>        " uploading file '" & _
>        source_file & "' to '" & _
>        dest_file & "'." & vbCrLf & Err.Description, _
>        vbExclamation Or vbOKOnly, _
>        "Download Error"
>    UploadFile = False
>    Exit Function
>End Function
>
>The problem is that when I try to execute this code from the
>computer in my work (directly connected to the Internet) the
>code is executed without any problem.
>When I try though to run the code from my home computer
>the code doesn't execute (no file is uploaded).
>From my home I connect to the Internet with a lan (computer
>connected to a switch which is conected to the ADSL Rooter).
>I am able to retrieve information with IntTransfContr from the
>Internet but I cannot upload. Any suggestions? 
>

0
Reply drshell (102) 3/15/2008 3:19:20 AM


1 Replies
22 Views

(page loaded in 0.027 seconds)


Reply: