Jump to content

Why my inet ftp can't send other file besides .txt format file?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Yan870126

Yan870126

    Newbie

  • Members
  • Pip
  • 8 posts
Hi,
please help. this is the code i get from internet, i tried it b4 it just works with .txt format, it can't allow me to send other file format e.g. : .jpg, .m2p, . mpl...and so on. please help

thank you in advance.:)

Option Explicit


Private m_GettingDir As Boolean

Private Sub AddMessage(ByVal msg As String)

    txtResults.Text = txtResults.Text & vbCrLf & msg

    txtResults.SelStart = Len(txtResults.Text)

End Sub


Private Sub cmdDownload_Click()

Dim host_name As String


    Enabled = False

    MousePointer = vbHourglass

    txtResults.Text = "Working"

    txtResults.SelStart = Len(txtResults.Text)

    DoEvents


    ' You must set the URL before the user name and

    ' password. Otherwise the control cannot verify

    ' the user name and password and you get the error:

    '

    '       Unable to connect to remote host

    host_name = txtHost.Text

    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name

    inetFTP.URL = host_name


    inetFTP.UserName = txtUserName.Text

    inetFTP.Password = txtPassword.Text


    ' Do not include the host name here. That will make

    ' the control try to use its default user name and

    ' password and you'll get the error again.

    inetFTP.Execute , "Get " & _

        txtRemoteFile.Text & " " & txtLocalFile.Text


'    m_GettingDir = True

'    inetFTP.Execute , "Dir"

End Sub


Private Sub cmdUpload_Click()

Dim host_name As String


    Enabled = False

    MousePointer = vbHourglass

    txtResults.Text = "Working"

    txtResults.SelStart = Len(txtResults.Text)

    DoEvents


    ' You must set the URL before the user name and

    ' password. Otherwise the control cannot verify

    ' the user name and password and you get the error:

    '

    '       Unable to connect to remote host

    host_name = txtHost.Text

    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name

    inetFTP.URL = host_name


    inetFTP.UserName = txtUserName.Text

    inetFTP.Password = txtPassword.Text


    ' Do not include the host name here. That will make

    ' the control try to use its default user name and

    ' password and you'll get the error again.

    inetFTP.Execute , "Put " & _

        txtLocalFile.Text & " " & txtRemoteFile.Text


'    m_GettingDir = True

'    inetFTP.Execute , "Dir"

End Sub

Private Sub inetFTP_StateChanged(ByVal State As Integer)

    Select Case State

        Case icError

            AddMessage "Error: " & _

                "    " & inetFTP.ResponseCode & vbCrLf & _

                "    " & inetFTP.ResponseInfo

        Case icNone

            AddMessage "None"

        Case icConnecting

            AddMessage "Connecting"

        Case icConnected

            AddMessage "Connected"

        Case icDisconnecting

            AddMessage "Disconnecting"

        Case icDisconnected

            AddMessage "Disconnected"

        Case icRequestSent

            AddMessage "Request Sent"

        Case icRequesting

            AddMessage "Requesting"

        Case icReceivingResponse

            AddMessage "Receiving Response"

        Case icRequestSent

            AddMessage "Request Sent"

        Case icResponseReceived

            AddMessage "Response Received"

        Case icResolvingHost

            AddMessage "Resolving Host"

        Case icHostResolved

            AddMessage "Host Resolved"


        Case icResponseCompleted

            AddMessage inetFTP.ResponseInfo


            If m_GettingDir Then

                Dim txt As String

                Dim chunk As Variant


                m_GettingDir = False


                ' Get the first chunk.

                chunk = inetFTP.GetChunk(1024, icString)

                DoEvents

                Do While Len(chunk) > 0

                    txt = txt & chunk

                    chunk = inetFTP.GetChunk(1024, icString)

                    DoEvents

                Loop


                AddMessage "----------"

                AddMessage txt

            End If


       Case Else

            AddMessage "State = " & Format$(State)

    End Select


    Enabled = True

    MousePointer = vbDefault

End Sub



#2
jashsayani

jashsayani

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
It should allow .jpg

Other compressed formats would not be allowed by your host.

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I may have missed it but I don't see where you switch to binary mode for anything other than ASCII (which are just text files). This may be your problem if files such as JPG/GIF/EXE are not being sent correctly.

#4
Yan870126

Yan870126

    Newbie

  • Members
  • Pip
  • 8 posts
Hi all, thanks for replied. but i'd found a better way to use the FTP. and I'll shared it to here.
1st of all you might need to get the module file in the attachment.
and declare this variables in your form

'all declare as public

Public curRemark As Integer

Dim hOpen As Long, hConnection As Long

Dim dwtype As Long


'declare this in ur private

hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)

Dim Server, user, password As String

Dim pData As WIN32_FIND_DATA

Dim bRet As Boolean

then open the connection in ur sub

'this is how they (open connection to ftp)

            hConnection = InternetConnect(hOpen, Server, INTERNET_INVALID_PORT_NUMBER, _

            user, password, INTERNET_SERVICE_FTP, 0, 0)


then you can send

bRet = FtpPutFile(hConnection, Radd, file, _

            dwtype, 0)

Radd = my located path to send the files.
file = the file name i want to send to the client file.(while ur file arrive client ftp directory it is the file name tat shown)
Server = the server address.
user = user name that set to access the ftp connection
password = is the password for this particular "user"

i only tried this in my LAN it works. but 1stly need to setup ftp for your PC 1st. please refer to xp_pro_ftp.pdf as attached. even a big file it works **** fast:thumbup:
try it.:thumbup1:

Attached Files