473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

issue when using code to FTP file to another server.

I am using the following code to FTP a file from one server to another:

Expand|Select|Wrap|Line Numbers
  1. Private Function createDataSocket() As Socket
  2. sendCommand("PASV")
  3. If retValue <> 227 Then
  4. Throw New IOException(reply.Substring(4))
  5. End If
  6. Dim index1 As Integer = reply.IndexOf("("c)
  7. Dim index2 As Integer = reply.IndexOf(")"c)
  8. Dim ipData As String = reply.Substring(index1 + 1, index2 - index1 - 1)
  9. Dim parts As Integer() = New Integer(5) {}
  10. Dim len As Integer = ipData.Length
  11. Dim partCount As Integer = -1
  12. Dim buf As String = ""
  13. Dim i As Integer = 0
  14. While i < len AndAlso partCount <= 6
  15. Dim ch As Char = [Char].Parse(ipData.Substring(i, 1))
  16. If [Char].IsDigit(ch) Then
  17. buf += ch
  18. ElseIf ch <> ","c Then
  19. Throw New IOException("Malformed PASV reply: " & reply)
  20. End If
  21. If ch = ","c OrElse i + 1 = len Then
  22. Try
  23. parts(System.Math.Max(System.Threading.Interlocked.Increment(partCount), partCount - 1)) = Int32.Parse(buf)
  24. buf = ""
  25. Catch generatedExceptionName As Exception
  26. Throw New IOException("Malformed PASV reply: " & reply)
  27. End Try
  28. End If
  29. i += 1
  30. End While
  31. Dim ipAddress As String = (((CStr(parts(0)) & ".") + CStr(parts(1)) & ".") + CStr(parts(2)) & ".") + CStr(parts(3))
  32. Dim port As Integer = (parts(4) << 8) + parts(5)
  33. Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  34. Dim ep As New IPEndPoint(Dns.Resolve(ipAddress).AddressList(0), port)
  35. Try
  36. s.Connect(ep)
  37. Catch generatedExceptionName As Exception
  38. Throw New IOException("Can't connect to remote server")
  39. End Try
  40. Return s
  41. End Function
  42.  
  43.  
the connections are all OK and I verified that the ID and password are fine, however, in this TRY...CATCH block, I get an out of bounds error:

Expand|Select|Wrap|Line Numbers
  1. Try
  2. parts(System.Math.Max(System.Threading.Interlocked.Increment(partCount), partCount - 1)) = Int32.Parse(buf)
  3. buf = ""
  4. Catch generatedExceptionName As Exception
  5. Throw New IOException("Malformed PASV reply: " & reply)
  6. End Try
  7.  
I'm not sure I understand why. All I have is a simple text file, that has "How are you?" in it. I want to test this code by FTPing this test.txt file from my server to another server.

Can you assist?
Jun 10 '13 #1
3 1203
Rabbit
12,516 Expert Mod 8TB
What is the value of partCount when the error is thrown? I'm betting it's out of bounds. Seeing as how it can be anywhere between -1 and 7 where as your array is only an Integer(5).
Jun 10 '13 #2
PartsCount = 6, but Parts array is Parts(7). Where does 7 come from?

I guess my issue is, I'm not exactly sure what this line of code is doing:
Expand|Select|Wrap|Line Numbers
  1. parts(System.Math.Max(System.Threading.Interlocked.Increment(partCount), partCount - 1)) = Int32.Parse(buf)
  2.  
If I step thru in debug mode, ipData has the following in it:
158,57,168,75,22,221 (len=20)
PartsCount starts at 0 and crashes when it is 6.
The PARTS array is PARTS(7) which is why it fails. As there are only 6 elements defined, it goes out of bounds, but I don't understand why.
I guess my question really is what does
Expand|Select|Wrap|Line Numbers
  1. System.Math.Max(System.Threading.Interlocked.Increment(partCount), partCount - 1)
  2.  
do?
Jun 10 '13 #3
Rabbit
12,516 Expert Mod 8TB
I don't know where you got parts(7) from. Your parts array is only an integer(5). Look at line 9. If partsCount is 6, you're out of range because your array is only array(5) not 7. I don't know where the 7 you mentioned comes from.
Jun 11 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bill | last post by:
I have perhaps not explained myself clearly, so I'll try it this way. In the code below, where it says "I'd like to include my navigation bar here" is the place I'd like to insert a navigation bar...
4
by: Benjamin Joldersma | last post by:
Hi all, If I have a expensive public property that exposes a collection, say via a call to a database: public ArrayList Complex { get { //expensive call to db
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
2
by: thehuby | last post by:
I am building a CMS and as part of it a user can upload an image. Once uploaded I am displaying the image. If the user then decides they want to replace the image with another I get a caching...
1
by: Andyza | last post by:
With reference to the ASPFAQ 2161 article - http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html Does the 'Content-Disposition' code work if the...
4
by: Geoff Lane | last post by:
Development environment: Windows 2003 Server running IIS6 and the same server running as a domain controller, DNS and DHCP servers. Production environment: Windows 2000 Server SP4 running IIS5...
0
by: =?Utf-8?B?d2lsbGlhbQ==?= | last post by:
Hi, I'm not sure if this is bug or not. I have a asp.net page which use AJAX CalenderExtender control for user to select a date. There is also a CrystalReportViewer control on this page, which...
0
by: rote | last post by:
When using the PassWord recvovery server control do we need to set the enablePasswordRetrieval attribute to false or True of the configured membership?
7
by: xraive | last post by:
Currently I only get the file path. Is there way to retrieve the file name or do I have to just use the split function. Dim fDialog As Office.FileDialog Dim varFile As Variant ...
0
by: lgwapnitsky | last post by:
I am writing an Outlook add-in that needs to fire when a PST is added/removed. I have successfully fired the event using the AddStore and RemoveStore functions, as well as when I use the "Open ->...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...

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.