Solved

Upload Files to Web...

Posted on 2003-11-04
11
214 Views
Last Modified: 2010-05-03
I've got an application I'm writing in visual studio for web-management purposes. The application is part of a larger application we have created with seperate sections for each of the day-to-day operations here at my company. The particular section I'm working on is for image additions, deletions, and replacement on our database driven website. Everything works fine other than the function to upload images to the FTP server. I have very limited knowledge on FTP and I don't need all the functionality of an FTP client. I simply want to be able to upload one image at a time to the server. I don't have a whole lot of points to offer, so I offered what I could afford. Any help will be greatly appreciated.
0
Comment
Question by:JimHERBEAU
  • 3
  • 3
  • 2
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9681609
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
ID: 9683526
Add a component named Microsoft Internet Transfer Control to your form,
Then

  Inet1.RemoteHost = "ftp://www.duck.org"
  Inet1.URL = "ftp://www.duck.org/
  Inet1.UserName = "LoginName"
  Inet1.Password = "password"
  Inet1.Protocol = icFTP
  Inet1.Execute "ftp://www.duck.org/">ftp://www.duck.org/", _
    "PUT C:\TestFile.txt TestFile.txt"

~ fantasy ~
0
 

Author Comment

by:JimHERBEAU
ID: 9687137
Whats the actual component file name (I.E. msitp.dll)? I can't find one that has the description name you gave.
0
Technology Partners: 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!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9687283
Do a right click on toolbox and choose add...
Locate Microsoft Internet Transfer control
0
 

Author Comment

by:JimHERBEAU
ID: 9687371
I'm using Visual Studio 2002 with VB.net and couldn't find that control anywhere, nor anyone who claims it's in any version of VB past VB 6.0
Thanks for the help though.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9687447
At least, all solutions posted here were for VB6 not .net!!!!
There is a .Net TA here, at EE, look at it.
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9691401
0
 

Author Comment

by:JimHERBEAU
ID: 9694109
I got it working playing around with some of the other components in VS

  Private mNetStream As NetworkStream
    Private mBytes() As Byte

    Public Function FtpCommand(ByVal strCommand As String) As String
        If mConnected Then
            Try
                Erase mBytes
                RaiseEvent ServerCalled(strCommand & vbCrLf)
                mBytes = Encoding.ASCII.GetBytes(strCommand & vbCrLf)
                mNetStream.Write(mBytes, 0, mBytes.Length)
                FtpCommand = GetResponse()
            Catch err As Exception
                RaiseEvent ErrorOccured(EC.FTPCommandFailed, err.ToString())
            End Try
        End If
    End Function

    Private Function OtherPortPut(ByVal intDataPort As Int32, ByVal strFN As String, Optional ByVal BytesWillRec As Int64 = 0) As MemoryStream
        Dim strTemp As String
        Dim i As Int64
        Dim priSM As New MemoryStream()
        Dim priSM1 As FileStream
        Dim intTmp As Integer

        If BytesWillRec >= 0 Then
            Try
                ReDim mBytes(FileLen(strFN))

                priSM1 = File.OpenRead(strFN)
                intBytesRec = priSM1.Read(mBytes, 0, FileLen(strFN))
                priSM.Write(mBytes, 0, mBytes.Length - 1)
                priSM.WriteTo(mDataStream)


                mDataStream.Close()
                OtherPortPut = priSM
                mTCPData.Close()
            Catch err As Exception
                RaiseEvent ErrorOccured(EC.UploadFailed, err.ToString())
            End Try
        Else
            RaiseEvent ErrorOccured(EC.InvalidFileLength, "Invalid declared file length!")
        End If
    End Function

  Public Function FtpPutFile(ByVal strFile As String, ByVal strDest As String, ByVal intSize As Long) As MemoryStream
        Dim priSM As New MemoryStream()
        Dim strTemp As String
        Dim i, j As Int16
        Dim intPort As Int32

        If mConnected Then
            Try
                strTemp = FtpCommand("TYPE I")
                intPort = cmdPasv2Port()
                strTemp = FtpCommand("STOR " & strDest)
                i = mFTPResponse.LastIndexOf(")", mFTPResponse.Length - 1)
                j = mFTPResponse.LastIndexOf("(", i)
                i = mFTPResponse.IndexOf(" ", j)
                strTemp = mFTPResponse.Substring(j + 1, i - j - 1)

                priSM = OtherPortPut(intPort, strFile, intSize)
                FtpPutFile = priSM

                strTemp = GetResponse()
                If strTemp.Substring(0, 4) <> "226 " Then
                    RaiseEvent ErrorOccured(EC.DownUpLoadFailure, "Transfer failure!")
                End If
            Catch err As Exception
                RaiseEvent ErrorOccured(EC.FTPPutFileFailed, err.ToString())
            End Try
        End If
    End Function
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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

679 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