Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-24
9
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Assisted Solution

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

Assisted Solution

by:imessvb
imessvb earned 150 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 900 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 3

Assisted Solution

by:nichia
nichia earned 900 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 450 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

730 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