Solved

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

Posted on 2004-08-24
9
288 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 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

14 Experts available now in Live!

Get 1:1 Help Now