Solved

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

Posted on 2004-08-24
9
291 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 115
How to Add / Edit Windows Menu 4 73
fso.FolderExists("\\server\HiddenFolder$") 4 88
Sub or Function is not defined 6 54
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

749 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