Solved

Upload Files to Web...

Posted on 2003-11-04
11
210 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
Comment Utility
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
Comment Utility
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
Comment Utility
Whats the actual component file name (I.E. msitp.dll)? I can't find one that has the description name you gave.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Do a right click on toolbox and choose add...
Locate Microsoft Internet Transfer control
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:JimHERBEAU
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:JimHERBEAU
Comment Utility
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

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!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now