Can't Upload File to ftp server using Windows Internet Transfer Control

I want to automate the uploading of a file to an ftp server external to our LAN (one of our clients). To test the application, I have first attempted to upload a test file to an ftp server on our company's LAN, one I have "write" privileges to.  

I can manually upload the test file in 2 ways:  1) With the DOS shell ftp send command and 2)accessing the server through IE explorer and using "drag and drop".  In both cases, I use a logon name and password that gives me this privilege.

In trying to create a program to automate this, I have added the Microsoft Internet Transfer Control to a visual basic form and use the following code in the Form Load event:

With Inet1
           .AccessType = icUseDefault
           .Protocol = icFTP
           .URL = "ftp.lanserver.com"
           .Username = "username" 'same user name I use to manually upload the file
           .Password = "password" 'same password I use to manually upload the file
           .Execute "ftp://ftp.lanserver.com", "PUT c:\TestFile.txt /uploadedtest.txt"
    End With
I get back the error message: "Cannot connect with the server." If Ireplace the server URL with the IP address I get the same error.
If I replace the Execute statement with: ".Execute "PUT c;\TestFile.txt /uploadedtest.txt", relying on the Execute command to use the URL set previously, nothing happens.  No upload and no error message.

I have also checked to make sure the TestFile.txt does indeed exist on the local C: drive.

Any ideas will be greatly appreciated.

Thanks,

John
Johnny6000Asked:
Who is Participating?
 
zzzzzoocConnect With a Mentor Commented:
Try the PAQ here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20829778.html

If the problem persists with the example in the above link, it's probably an issue with the ftp-server. Possible misconfigured permissions, incorrect port and so forth. Check Inet1.ResponseInfo for icResponseCompleted or the ftp-server logs.
0
 
imessvbConnect With a Mentor Commented:
0
 
imessvbConnect With a Mentor Commented:
(oops...)
that is to say, either

inet1.execute "ftp://username:password@ftp.lanserver.com", "PUT c:\TestFile.txt /uploadedtest.txt"

or

With Inet1
           .AccessType = icUseDefault
           .Protocol = icFTP
           .URL = "ftp.lanserver.com"
           .Username = "username" 'same user name I use to manually upload the file
           .Password = "password" 'same password I use to manually upload the file
           .Execute , "PUT c:\TestFile.txt /uploadedtest.txt"
End With

or

With Inet1
           .AccessType = icUseDefault
           .Protocol = icFTP
           .URL = "ftp://username:password@ftp.lanserver.com"
           .Execute , "PUT c:\TestFile.txt /uploadedtest.txt"
End With
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nichiaConnect With a Mentor Commented:
This works for me:

(don't forget the comma after Execute if you leave off the URL)

Private Sub Command1_Click()
On Error GoTo errhandler
With Inet1
    .AccessType = icUseDefault
    .RemotePort = 21
    .Protocol = icFTP
    .URL = "ftp://ftp.foo.com"
    .UserName = "userrrr"
    .Password = "passsss"
    .Execute , "PUT c:\testfile.txt /uploadedtest.txt"
    Call Wait
    .Execute , "quit"
    Call Wait
End With
    Exit Sub
errhandler:
    Debug.Print "Error: " & Err.Number & " " & Err.Description
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Debug.Print State
End Sub

Private Sub Wait()
    Screen.MousePointer = vbHourglass
    Do While Inet1.StillExecuting = True
        DoEvents
    Loop
    Screen.MousePointer = vbDefault
End Sub
0
 
Johnny6000Author Commented:
To richia:  Well, we're halfway there.  I tried your code, which is pretty similar to what I already had, but was unsuccessful in uploading "Test.txt" to the LAN ftp server.  However, when I manually placed  "TestFile.txt"   on the LAN ftp server and substituted: .Execute , "Get TestFile.txt c:\uploadedtest.txt" for .Execute , "PUT c:\TestFile.txt /uploadedtest.txt" in the vb program, I was able to programmatically download "TestFile.txt" to the C: drive and  rename it to "uploadedtest.txt".

Now whiy can I download but not upload, since I have permissions to do both?  And, what can I do about it?

John
0
 
nichiaConnect With a Mentor Commented:
Odd

Try using the StateChanged event to trace the upload...

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Dim sState As String
   
    On Error Resume Next
    Select Case State
           Case icNone
           Case icResolvingHost:      sState = "Resolving Host"
           Case icHostResolved:       sState = "Host Resolved"
           Case icConnecting:         sState = "Connecting..."
           Case icConnected:          sState = "Connected"
           Case icResponseReceived:   sState = "Transferring File..."
           Case icDisconnecting:             sState = "Disconnecting..."
           Case icDisconnected:              sState = "Disconnected"
           Case icError:  sState = "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
           Case icResponseCompleted:  sState = "Process Complete."
    End Select
    Err.Clear
    If (sState <> "") Then
        Debug.Print sState
    End If

End Sub



This is what it prints out on my test:

Connecting...
Connected
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Process Complete.
Disconnecting...
Disconnected

0
 
Johnny6000Author Commented:
OK, here's what I get when I attempt to upload to the internal server:

Resolving Host
Host Resolved
Connecting...
Connected
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Transferring File...
Process Complete.
Disconnecting...

However, no cigar.  The file is not uploaded.  I am upping the point value to 500 points.  John
Disconnected

0
 
Johnny6000Author Commented:
I don't have access to the servers I am trying to upload to, either on the LAN or outside of it.  I know that ftp root properties have a Write checkbox that must be checked in order to allow uploads.  The default value is unchecked: I checked my local ftp root properties, but I think this has only to do with what I allow on my server, not on the ones I'm trying to access.  
The default value is unchecked, and I suspect that both the target servers have the Write property unchecked; but if this is true then why can I manually upload, but not programmatically?
Well, I'm going to start a new thread with the wininet program which will upload to the LAN server but gives me an "Access Denied" error message when I try to upload the same file to the client's ftp server.
0
 
Johnny6000Author Commented:
The problem must be due to the servers I am trying to ftp to, but I have no control over them.  Thanks for your help, everybody!

John
0
All Courses

From novice to tech pro — start learning today.