473,708 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FTP - can't upload a file using the MS Example

Jen
I'm using Microsoft's own VB.NET FTP Example:

http://support.microsoft.com/default...b;en-us;832679

I can get the program to create directories, change directories, etc.,
but I can't get it to upload a file to the FTP server. I just get a
"Cannot connect to remote server" error after this TRY:

s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
ep = New IPEndPoint(Dns. Resolve(ipAddre ss).AddressList (0),
port)

Try
s.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Ca nnot connect to remote server.")

As I said, it'll do a directory list, create, change, and delete
directories, but it will NOT transfer a file, and that's what I need
it to do. I have the code set up properly for VS 2003, per the
comments for the port calculations, and even tried it the VS 2002 way
just to be sure that wasn;t the problem.

I've also tried the Indy FTP client, but it won't even do a directory
list (says the machine "actively refused" the connection).

If someone could help I'd appreciate it.
(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/
Nov 21 '05 #1
18 4345
Hi Jen,

This apparently seems to be the connectivity issue.
Try to access the FTP using command prompt without using some FTP explorer.

If that doesnt work then the issue is with the connectivity (firewall or
something ) rather than code problem.

HTH
rawCoder

"Jen" <no***********@ gte.net> wrote in message
news:n3******** *************** *********@4ax.c om...
I'm using Microsoft's own VB.NET FTP Example:

http://support.microsoft.com/default...b;en-us;832679

I can get the program to create directories, change directories, etc.,
but I can't get it to upload a file to the FTP server. I just get a
"Cannot connect to remote server" error after this TRY:

s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
ep = New IPEndPoint(Dns. Resolve(ipAddre ss).AddressList (0),
port)

Try
s.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Ca nnot connect to remote server.")

As I said, it'll do a directory list, create, change, and delete
directories, but it will NOT transfer a file, and that's what I need
it to do. I have the code set up properly for VS 2003, per the
comments for the port calculations, and even tried it the VS 2002 way
just to be sure that wasn;t the problem.

I've also tried the Indy FTP client, but it won't even do a directory
list (says the machine "actively refused" the connection).

If someone could help I'd appreciate it.
(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/

Nov 21 '05 #2
Jen
I can use WS_FTP to upload/download files, so I don't think it's a
connectivity issue.
"rawCoder" <ra******@hotma il.com> wrote: Hi Jen,

This apparently seems to be the connectivity issue.
Try to access the FTP using command prompt without using some FTP explorer.

If that doesnt work then the issue is with the connectivity (firewall or
something ) rather than code problem.

HTH
rawCoder

(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/
Nov 21 '05 #3
Hi,

The files that it tries to upload dont exist on my machine. I had
to create them. Are you the files you are trying to upload exist?

Ken
-------------------
"Jen" <no***********@ gte.net> wrote in message
news:n3******** *************** *********@4ax.c om...
I'm using Microsoft's own VB.NET FTP Example:

http://support.microsoft.com/default...b;en-us;832679

I can get the program to create directories, change directories, etc.,
but I can't get it to upload a file to the FTP server. I just get a
"Cannot connect to remote server" error after this TRY:

s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
ep = New IPEndPoint(Dns. Resolve(ipAddre ss).AddressList (0),
port)

Try
s.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Ca nnot connect to remote server.")

As I said, it'll do a directory list, create, change, and delete
directories, but it will NOT transfer a file, and that's what I need
it to do. I have the code set up properly for VS 2003, per the
comments for the port calculations, and even tried it the VS 2002 way
just to be sure that wasn;t the problem.

I've also tried the Indy FTP client, but it won't even do a directory
list (says the machine "actively refused" the connection).

If someone could help I'd appreciate it.
(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/
Nov 21 '05 #4
Hi Ken,

Are you taken it over from me? Sometimes not typing all words.
The files that it tries to upload dont exist on my machine. I had
to create them. Are you the files you are trying to upload exist?

The files that it tries to upload dont exist on my machine. I had to create
them. Are you sure that the files you are trying to upload exist?

probably?

:-)

Cor
Nov 21 '05 #5
Jen
Yes. I created them and the directory on my machine.

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote: Hi,

The files that it tries to upload dont exist on my machine. I had
to create them. Are you the files you are trying to upload exist?

Ken


(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/
Nov 21 '05 #6
Jen
I think I have it working (so far anyway). It wasn't the code at all
- it was the server I was connecting to. Unbeknownst to me, comcast
had changed the name of their FTP servers from
"mywebpages.com cast.net" to "upload.comcast .net". Evidently it's
still a work in progress, as the "mywebpages " server will still come
up for directory functions, but won't allow me tp upload.

Thanks to everyone that tried to help, I do appreciate it!


(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/
Nov 21 '05 #7
Jen,

Is it working? I have the same problem - in the MS app, an error comes up
when trying to create a data socket (your given code). I manage to trace it
to one of two causes: the target machine actively refusing connection, or
just taking too long to respond. For some reason, the error returned is the
more general (and vague)
"Cannot connect to remote server". Damn irritating.

But I've tried it with four different FTP sites having verified usernames
and passwords and no-go. Unlikely that all four server names are changing. So
if you have since figured it out, I'd appreciate you letting me know any
discoveries you've since made.

Cheers, Richard

PS! Is the "dim the lights" msg your own or an advertising blurb?

"Jen" wrote:
I think I have it working (so far anyway). It wasn't the code at all
- it was the server I was connecting to. Unbeknownst to me, comcast
had changed the name of their FTP servers from
"mywebpages.com cast.net" to "upload.comcast .net". Evidently it's
still a work in progress, as the "mywebpages " server will still come
up for directory functions, but won't allow me tp upload.

Thanks to everyone that tried to help, I do appreciate it!


(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/

Nov 21 '05 #8
Jen,

Aargh! Here goes a 2nd time (MS just dropped my first reply).
I've had the same problem. By examing the error messages in the debugging
window when it got to the code sample you displayed (the create data socket
procedure), it seems to say either that the connection was actively refused
by target machine, or that it took too long to respond.

Now I've tried this with 3 other FTP fites and the same error occurs, so
it's unlikely that the FTP servers are all renaming their servers in my case.
Is your problem fixed? If it wasn't the server being renamed, did you find
out what the problem was? I'd really appreciate your help, since this is
driving me crazy.

Cheers, Richard

PS! The Dim the Lights msg your own, or was that advertising blurb?

"Jen" wrote:
I'm using Microsoft's own VB.NET FTP Example:

http://support.microsoft.com/default...b;en-us;832679

I can get the program to create directories, change directories, etc.,
but I can't get it to upload a file to the FTP server. I just get a
"Cannot connect to remote server" error after this TRY:

s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
ep = New IPEndPoint(Dns. Resolve(ipAddre ss).AddressList (0),
port)

Try
s.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Ca nnot connect to remote server.")

As I said, it'll do a directory list, create, change, and delete
directories, but it will NOT transfer a file, and that's what I need
it to do. I have the code set up properly for VS 2003, per the
comments for the port calculations, and even tried it the VS 2002 way
just to be sure that wasn;t the problem.

I've also tried the Indy FTP client, but it won't even do a directory
list (says the machine "actively refused" the connection).

If someone could help I'd appreciate it.
(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/

Nov 21 '05 #9
This class is FTP.

I hope it will help you and others.

Imports System.Net

Imports System

Imports System.IO

Imports System.Text

Imports System.Net.Sock ets
Public Class clsFTP

#Region "Main Class Variable Declarations"

Private m_sRemoteHost, m_sRemotePath, m_sRemoteUser As String

Private m_sRemotePasswo rd, m_sMess As String

Private m_iRemotePort, m_iBytes As Int32

Private m_objClientSock et As Socket

Private m_iRetValue As Int32

Private m_bLoggedIn As Boolean ' Change to loggedIn

Private m_sMes, m_sReply As String

Private FilePath As String
' Set the size of the packet that is used to read and

' write data to the FTP Server to the spcified size below.

Public Const BLOCK_SIZE = 512

Private m_aBuffer(BLOCK _SIZE) As Byte

Private ASCII As Encoding = Encoding.ASCII

' General variables

Private m_sMessageStrin g As String

#End Region

#Region "Class Constructors"

'

' Main class constructor.

Public Sub New()

m_sRemoteHost = "10.10.10.1 0"

m_sRemotePath = "."

m_sRemoteUser = "username"

m_sRemotePasswo rd = "password"

m_sMessageStrin g = ""

m_iRemotePort = 21

m_bLoggedIn = False

End Sub

' Parametized constructor.

Public Sub New(ByVal sRemoteHost As String, ByVal sRemotePath As
String, ByVal sRemoteUser As String, ByVal sRemotePassword As String,
ByVal iRemotePort As Int32)

m_sRemoteHost = sRemoteHost

m_sRemotePath = sRemotePath

m_sRemoteUser = sRemoteUser

m_sRemotePasswo rd = sRemotePassword

m_sMessageStrin g = ""

m_iRemotePort = iRemotePort

m_bLoggedIn = False

End Sub

#End Region

#Region "Public Properties"

'

' Set/Get the name of the FTP Server.

Public Property RemoteHost() As String

Get

Return m_sRemoteHost

End Get

Set(ByVal Value As String)

m_sRemoteHost = Value

End Set

End Property

' Set/Get the FTP Port Number.

Public Property RemotePort() As Int32

Get

Return m_iRemotePort

End Get

Set(ByVal Value As Int32)

m_iRemotePort = Value

End Set

End Property

' Set/Get the remote path.

Public Property RemotePath() As String

Get

Return m_sRemotePath

End Get

Set(ByVal Value As String)

m_sRemotePath = Value

End Set

End Property

' Set the remote password.

Public Property RemotePassword( ) As String

Get

Return m_sRemotePasswo rd

End Get

Set(ByVal Value As String)

m_sRemotePasswo rd = Value

End Set

End Property

' Set/Get the remote user.

Public Property RemoteUser() As String

Get

Return m_sRemoteUser

End Get

Set(ByVal Value As String)

m_sRemoteUser = Value

End Set

End Property

' Set the class messagestring.

Public Property MessageString() As String

Get

Return m_sMessageStrin g

End Get

Set(ByVal Value As String)

m_sMessageStrin g = Value

End Set

End Property

#End Region

#Region "Public Subs and Functions"

'

' Return a list of files within a string() array from the

' file system.

Public Function GetFileList(ByV al sMask As String) As String()
MsgBox(sMask)

Dim cSocket As Socket

Dim bytes As Int32

Dim seperator As Char = ControlChars.Lf

Dim mess() As String

m_sMes = ""

If (Not (m_bLoggedIn)) Then

Login()

End If

cSocket = CreateDataSocke t()

'SendCommand("{ ls -ls}")




If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

m_sMes = ""

Do While (True)

m_aBuffer.Clear (m_aBuffer, 0, m_aBuffer.Lengt h)

bytes = cSocket.Receive (m_aBuffer, m_aBuffer.Lengt h, 0)

m_sMes += ASCII.GetString (m_aBuffer, 0, bytes)

If (bytes < m_aBuffer.Lengt h) Then

Exit Do

End If

Loop

mess = m_sMes.Split(se perator)

cSocket.Close()

ReadReply()

If (m_iRetValue <> 226) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

Return mess

End Function

'

' Get the size of the file on the FTP Server.

Public Function GetFileSize(ByV al sFileName As String) As Long

Dim size As Long

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("SI ZE " & sFileName)

size = 0

If (m_iRetValue = 213) Then

size = Int64.Parse(m_s Reply.Substring (4))

Else

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

Return size

End Function

Public Function GetFileDate(ByV al sFileName As String) As DateTime
If (Not (m_bLoggedIn)) Then
Login()
End If
SendCommand("MD TM " & sFileName)
Dim filepath As String = Me.m_sReply
Dim num2 As Integer = CInt(filepath.S ubstring(4, 4))
Dim num3 As Integer = CInt(filepath.S ubstring(8, 2))
Dim num4 As Integer = CInt(filepath.S ubstring(10, 2))
Dim num5 As Integer = CInt(filepath.S ubstring(12, 2))
Dim num6 As Integer = CInt(filepath.S ubstring(14, 2))
returnedfiledat e = DateTime.Parse( num3 & "/" & num4 & "/" & num2
& " " & num5 & ":" & num6)
Return returnedfiledat e
End Function

' Log into the FTP Server.

Public Function Login() As Boolean

m_objClientSock et = New Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p)

Dim ep As New
IPEndPoint(Dns. Resolve(m_sRemo teHost).Address List(0), m_iRemotePort)

Try

m_objClientSock et.Connect(ep)

Catch ex As Exception

MessageString = m_sReply

Throw New IOException("Co uldn't connect to remote server")

End Try

ReadReply()

If (m_iRetValue <> 220) Then

CloseConnection ()

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

SendCommand("US ER " & m_sRemoteUser)

If (Not (m_iRetValue = 331 Or m_iRetValue = 230)) Then

Cleanup()

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

If (m_iRetValue <> 230) Then

SendCommand("PA SS " & m_sRemotePasswo rd)

If (Not (m_iRetValue = 230 Or m_iRetValue = 202)) Then

Cleanup()

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

End If

m_bLoggedIn = True

ChangeDirectory (m_sRemotePath)

' Return the end result.

Return m_bLoggedIn

End Function

'

' If the value of mode is true, set binary mode for

' downloads.

' Else, set Ascii mode.

Public Sub SetBinaryMode(B yVal bMode As Boolean)

If (bMode) Then

SendCommand("TY PE I")

Else

SendCommand("TY PE A")

End If

If (m_iRetValue <> 200) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

End Sub

'

' Download a file to the Assembly's local directory,

' keeping the same file name.

Public Sub DownloadFile(By Val sFileName As String)

DownloadFile(sF ileName, "", False)

End Sub

'

' Download a remote file to the Assembly's local

' directory, keeping the same file name, and set

' the resume flag.

Public Sub DownloadFile(By Val sFileName As String, ByVal bResume As
Boolean)

DownloadFile(sF ileName, "", bResume)

End Sub

'

' Download a remote file to a local file name which can

' include a path. The local file name will be created or

' overwritten, but the path must exist.

Public Sub DownloadFile(By Val sFileName As String, ByVal
sLocalFileName As String)

DownloadFile(sF ileName, sLocalFileName, False)

End Sub

'

' Download a remote file to a local file name which can

' include a path, and set the resume flag. The local file

' name will be created or overwritten, but the path must

' exist.

Public Sub DownloadFile(By Val sFileName As String, ByVal
sLocalFileName As String, ByVal bResume As Boolean)

Dim st As Stream

Dim output As FileStream

Dim cSocket As Socket

Dim offset, npos As Long

If (Not (m_bLoggedIn)) Then

Login()

End If

SetBinaryMode(T rue)

If (sLocalFileName .Equals("")) Then

sLocalFileName = sFileName
End If

If (Not (File.Exists(sL ocalFileName))) Then

st = File.Create(sLo calFileName)
st.Close()

End If

output = New FileStream(sLoc alFileName, FileMode.Open)

cSocket = CreateDataSocke t()

offset = 0

If (bResume) Then

offset = output.Length

If (offset > 0) Then

SendCommand("RE ST " & offset)

If (m_iRetValue <> 350) Then

'throw new IOException(rep ly.Substring(4) );

'Some servers may not support resuming.

offset = 0

End If

End If

If (offset > 0) Then

npos = output.Seek(off set, SeekOrigin.Begi n)

End If

End If

SendCommand("RE TR " & sFileName)

If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

Do While (True)

m_aBuffer.Clear (m_aBuffer, 0, m_aBuffer.Lengt h)

m_iBytes = cSocket.Receive (m_aBuffer, m_aBuffer.Lengt h, 0)

output.Write(m_ aBuffer, 0, m_iBytes)

If (m_iBytes <= 0) Then

Exit Do

End If

Loop

output.Close()

If (cSocket.Connec ted) Then

cSocket.Close()

End If

ReadReply()

If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

End Sub

'

' Upload a file.

Public Sub UploadFile(ByVa l sFileName As String)

UploadFile(sFil eName, False)

End Sub

'

' Upload a file and set the resume flag.

Public Sub UploadFile(ByVa l sFileName As String, ByVal bResume As
Boolean)

Dim cSocket As Socket

Dim offset As Long

Dim input As FileStream

Dim bFileNotFound As Boolean

If (Not (m_bLoggedIn)) Then

Login()

End If

cSocket = CreateDataSocke t()

offset = 0

If (bResume) Then

Try

SetBinaryMode(T rue)

offset = GetFileSize(sFi leName)

Catch ex As Exception

offset = 0

End Try

End If

If (offset > 0) Then

SendCommand("RE ST " & offset)

If (m_iRetValue <> 350) Then

'throw new IOException(rep ly.Substring(4) );

'Remote server may not support resuming.

offset = 0

End If

End If

SendCommand("ST OR " & Path.GetFileNam e(sFileName))

If (Not (m_iRetValue = 125 Or m_iRetValue = 150)) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

' Check to see if the file exists before the upload.

bFileNotFound = False

If (File.Exists(sF ileName)) Then

' Open input stream to read source file

input = New FileStream(sFil eName, FileMode.Open)

If (offset <> 0) Then

input.Seek(offs et, SeekOrigin.Begi n)

End If

' Upload the file

m_iBytes = input.Read(m_aB uffer, 0, m_aBuffer.Lengt h)

Do While (m_iBytes > 0)

cSocket.Send(m_ aBuffer, m_iBytes, 0)

m_iBytes = input.Read(m_aB uffer, 0, m_aBuffer.Lengt h)

Loop

input.Close()

Else

bFileNotFound = True

End If

If (cSocket.Connec ted) Then

cSocket.Close()

End If

' No point in reading the return value if the file was

' not found.

If (bFileNotFound) Then

MessageString = m_sReply

Throw New IOException("Th e file: " & sFileName & " was not
found. Can not upload the file to the FTP Site.")

End If

ReadReply()

If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

End Sub

'

' Delete a file from the remote FTP server.

Public Function DeleteFile(ByVa l sFileName As String) As Boolean

Dim bResult As Boolean

bResult = True

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("DE LE " & sFileName)

If (m_iRetValue <> 250) Then

bResult = False

MessageString = m_sReply

End If

' Return the final result.

Return bResult

End Function

'

' Rename a file on the remote FTP server.

Public Function RenameFile(ByVa l sOldFileName As String, ByVal
sNewFileName As String) As Boolean

Dim bResult As Boolean

bResult = True

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("RN FR " & sOldFileName)

If (m_iRetValue <> 350) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

' known problem

' rnto will not take care of existing file.

' i.e. It will overwrite if newFileName exist

SendCommand("RN TO " & sNewFileName)

If (m_iRetValue <> 250) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

Return bResult

End Function

'

' Create a directory on the remote FTP server.

Public Function CreateDirectory (ByVal sDirName As String) As Boolean

Dim bResult As Boolean

bResult = True

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("MK D " & sDirName)

If (m_iRetValue <> 257) Then

bResult = False

MessageString = m_sReply

End If

' Return the final result.

Return bResult

End Function

'

' Delete a directory on the remote FTP server.

Public Function RemoveDirectory (ByVal sDirName As String) As Boolean

Dim bResult As Boolean

bResult = True

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("RM D " & sDirName)

If (m_iRetValue <> 250) Then

bResult = False

MessageString = m_sReply

End If

' Return the final result.

Return bResult

End Function

'

' Change the current working directory on the remote FTP

' server.

Public Function ChangeDirectory (ByVal sDirName As String) As Boolean

Dim bResult As Boolean

bResult = True

If (sDirName.Equal s(".")) Then

Exit Function

End If

If (Not (m_bLoggedIn)) Then

Login()

End If

SendCommand("CW D " & sDirName)

If (m_iRetValue <> 250) Then

bResult = False

MessageString = m_sReply

End If

Me.m_sRemotePat h = sDirName

' Return the final result.

Return bResult

End Function

'

' Close the FTP connection.

Public Sub CloseConnection ()

If (Not (m_objClientSoc ket Is Nothing)) Then

SendCommand("QU IT")

End If

Cleanup()

End Sub

#End Region

#Region "Private Subs and Functions"

'

' Read the reply from the FTP Server

Private Sub ReadReply()

m_sMes = ""

m_sReply = ReadLine()
FilePath = m_sReply
m_iRetValue = Int32.Parse(m_s Reply.Substring (0, 3))

End Sub

'

' Clean up some variables.

Private Sub Cleanup()

If Not (m_objClientSoc ket Is Nothing) Then

m_objClientSock et.Close()

m_objClientSock et = Nothing

End If

m_bLoggedIn = False

End Sub

'

' Read a line from the server.

Private Function ReadLine(Option al ByVal bClearMes As Boolean =
False) As String

Dim seperator As Char = ControlChars.Lf

Dim mess() As String

If (bClearMes) Then

m_sMes = ""

End If

Do While (True)

m_aBuffer.Clear (m_aBuffer, 0, BLOCK_SIZE)

m_iBytes = m_objClientSock et.Receive(m_aB uffer,
m_aBuffer.Lengt h, 0)

m_sMes += ASCII.GetString (m_aBuffer, 0, m_iBytes)

If (m_iBytes < m_aBuffer.Lengt h) Then

Exit Do

End If

Loop

mess = m_sMes.Split(se perator)

If (m_sMes.Length > 2) Then

m_sMes = mess(mess.Lengt h - 2)

Else

m_sMes = mess(0)

End If

If (Not (m_sMes.Substri ng(3, 1).Equals(" "))) Then

Return ReadLine(True)

End If

Return m_sMes

End Function

'

' Send a command to the FTP Server.

Private Sub SendCommand(ByV al sCommand As String)

sCommand = sCommand & ControlChars.Cr Lf

Dim cmdbytes As Byte() = ASCII.GetBytes( sCommand)

m_objClientSock et.Send(cmdbyte s, cmdbytes.Length , 0)

ReadReply()

End Sub

'

' Create a Data socket.

Private Function CreateDataSocke t() As Socket

Dim index1, index2, len As Int32

Dim partCount, i, port As Int32

Dim ipData, buf, ipAddress As String

Dim parts(6) As Int32

Dim ch As Char

Dim s As Socket

Dim ep As IPEndPoint

SendCommand("PA SV")

If (m_iRetValue <> 227) Then

MessageString = m_sReply

Throw New IOException(m_s Reply.Substring (4))

End If

index1 = m_sReply.IndexO f("(")

index2 = m_sReply.IndexO f(")")

ipData = m_sReply.Substr ing(index1 + 1, index2 - index1 - 1)

len = ipData.Length

partCount = 0

buf = ""

For i = 0 To ((len - 1) And partCount <= 6)

ch = Char.Parse(ipDa ta.Substring(i, 1))

If (Char.IsDigit(c h)) Then

buf += ch

ElseIf (ch <> ",") Then

MessageString = m_sReply

Throw New IOException("Ma lformed PASV reply: " &
m_sReply)

End If

If ((ch = ",") Or (i + 1 = len)) Then

Try

parts(partCount ) = Int32.Parse(buf )

partCount += 1

buf = ""

Catch ex As Exception

MessageString = m_sReply

Throw New IOException("Ma lformed PASV reply: " &
m_sReply)

End Try

End If

Next

ipAddress = parts(0) & "." & parts(1) & "." & parts(2) & "." &
parts(3)

' Make this call in VB.NET 2002. We would like to

' bitshift the number by 8 bits, so in VB.NET 2002 we

' multiply the number by 2 to the power of 8.

'port = parts(4) * (2 ^ 8)

' Make this call and comment out the above line for

' VB.NET 2003.

port = parts(4) << 8

' Determine the data port number.

port = port + parts(5)

s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)

ep = New IPEndPoint(Dns. Resolve(ipAddre ss).AddressList (0), port)

Try
s.Connect(ep)

Catch ex As Exception

MessageString = m_sReply
MsgBox(ex.ToStr ing)

Throw New IOException("Ca n't connect to remote server")

End Try

Return s

End Function

#End Region

End Class
"RichardC" <Ri******@discu ssions.microsof t.com> wrote in message
news:96******** *************** ***********@mic rosoft.com:
Jen,

Is it working? I have the same problem - in the MS app, an error comes up

when trying to create a data socket (your given code). I manage to trace
it
to one of two causes: the target machine actively refusing connection, or

just taking too long to respond. For some reason, the error returned is
the
more general (and vague)
"Cannot connect to remote server". Damn irritating.

But I've tried it with four different FTP sites having verified usernames

and passwords and no-go. Unlikely that all four server names are changing.
So
if you have since figured it out, I'd appreciate you letting me know any

discoveries you've since made.

Cheers, Richard

PS! Is the "dim the lights" msg your own or an advertising blurb?

"Jen" wrote:
I think I have it working (so far anyway). It wasn't the code at all
- it was the server I was connecting to. Unbeknownst to me, comcast
had changed the name of their FTP servers from
"mywebpages.com cast.net" to "upload.comcast .net". Evidently it's
still a work in progress, as the "mywebpages " server will still come
up for directory functions, but won't allow me tp upload.

Thanks to everyone that tried to help, I do appreciate it!


(please send all replies via the newsgroup)

Dim the Lights & Save the Stars:
http://www.darksky.org/


Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3370
by: John | last post by:
I am using Excel to save a spreadsheet in .csv format. This creates a text file with extension .csv But when I try to upload the file to the server by checking for its MIME type using $_FILE I get my own error message that the file is not text file. If I change the extension to .txt I am able to upload the file. This is not reliable as it is only relying on extensions rather than contents of the file. Is there a reliable way of checking...
3
2677
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD" listing in my address book and (optionally) their name listed on my "news" page of my birtle.com website (listed as "Jane Smith is a Programming GOD") for at least a month. Why not take a moment to read more and possibly boost your ego to all time...
6
4889
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
6
10099
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is it possible to implement it using some other control, for example a floating window?
4
5487
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing. i have done this one.Now what i need is to enable the users to upload files and save it into the corresponding table. Example: 3. A laser inventory form has been completed for each 3b or 4 laser and submitted to the Laser Safety Officer...
1
2720
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the problem is that the server code can't read the httpfilecollection. the count is always zero. my upload form's form tag looks like this:
6
3332
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I upload it to a different web-server running RH 7.3 (an internal test-webserver), it works OK. The PDF document is created by OpenOffice 2.0 from a MS Word document. I have also had it converted to PDF in MS Word that could create PDF documents....
7
2365
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a camera or other, it uploads fine. However, If I want to rotate the image, or resize it with photoshop or simmilar, making sure to save it again as a jpg, the PHP upload won't upload the image.
3
1940
by: wassimdaccache | last post by:
Dear sirs, It is shame to me to say that I have been 1 week working in this problem and it is not working. I am getting this error while I am uploading a file using my website. Warning: copy( /home/wasstech/attachement/juj.doc) : failed to open stream: Operation not permitted in /home/wasstech/public_html/send.php on line 9 Error
0
8787
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9060
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2096
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.