Solved

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

Posted on 2004-08-24
9
287 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:Johnny6000
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Assisted Solution

by:imessvb
imessvb earned 50 total points
ID: 11888443
0
 

Assisted Solution

by:imessvb
imessvb earned 50 total points
ID: 11888463
(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
 
LVL 3

Assisted Solution

by:nichia
nichia earned 300 total points
ID: 11888523
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
 

Author Comment

by:Johnny6000
ID: 11893832
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Assisted Solution

by:nichia
nichia earned 300 total points
ID: 11894572
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
 

Author Comment

by:Johnny6000
ID: 11894725
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
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 150 total points
ID: 11895587
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
 

Author Comment

by:Johnny6000
ID: 11897656
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
 

Author Comment

by:Johnny6000
ID: 11897745
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now