473,322 Members | 1,736 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,322 software developers and data experts.

.NET FTP Object doing CD's..???

Hello all,

We are connecting to a remote server using FTP and sending up 100's of files
daily to this site. I just received a call from the operations manager of
this site and they are complaining that we are doing a CD.. in our
connection prior to uploading. Once we signon, they claim we are "in" the
correct folder. I have adopted this code from another programmer who is
long gone. I do not see anything in this code that would cause it to do a
CD.. once connected to the site and then do a CD into the appropriate
folder. Does the FTP object have a setting I can change that will get rid
of this behavior? We are calling the following class like:

Private _ftp As FtpClient
.....
_ftp = New Ftpclient(Me)
...._ftp.DoZipUpload()

Below is the code for the FtpClient class. Any ideas would be greatly
appreciated!
Imports System.Net

Imports System.IO

Public Class Ftpclient

Private Base As EtiBase

Sub New(ByRef aEtiBase As EtiBase)

Base = aEtiBase

End Sub

Public Sub DoZipUpload()

Base.LogToSummary("Uploading data.")

DoUpload(Base.Ini.outputzipfilename, Base.Ini.ftpuser,
Base.Ini.ftppasswordtext, Base.Ini.ftpserver, Base.Ini.ftppassive)

End Sub

Private Sub AttemptFtpConnect(ByVal username As String, ByVal password As
String, ByVal UsePassive As String, ByVal uploadUrl As String, ByRef
requestStream As Stream, ByRef uploadRequest As FtpWebRequest)

uploadRequest = Nothing

requestStream = Nothing

Try 'attempt connect

uploadRequest = WebRequest.Create(uploadUrl) 'set connection options

uploadRequest.Method = WebRequestMethods.Ftp.UploadFile

uploadRequest.Proxy = Nothing 'no proxy, no passive

uploadRequest.UsePassive = Convert.ToBoolean(UsePassive)

uploadRequest.Credentials = New NetworkCredential(username, password)

requestStream = uploadRequest.GetRequestStream()

Base.LogToSummary(vbCrLf & "FTP connect success.")

Catch ex As Exception

Base.LogToSummary(vbCrLf & "FTP connect failed.")

Base.LogToDebug(String.Format("exception! message:[{0}] source:[{1}]",
ex.Message, ex.Source))

End Try

End Sub

Private Sub DoUpload(ByVal fileName As String, ByVal username As String,
ByVal password As String, ByVal host As String, ByVal UsePassive As String)

Base.ParentForm.SetText("Attempting to connect to ftp...")

Base.LogToDebug(String.Format("ftp: host[{0}] user[{1}] password-length[{2}]
file[{3}]", host, username, password.Length, fileName))

Dim uploadUrl As String = "ftp://" & host & "/" & Path.GetFileName(fileName)

Dim requestStream As Stream = Nothing

Dim uploadRequest As FtpWebRequest = Nothing

'try to get ftp conenction

AttemptFtpConnect(username, password, UsePassive, uploadUrl, requestStream,
uploadRequest)

'retry if failed

If requestStream Is Nothing Then

Base.WaitForServer(host)

AttemptFtpConnect(username, password, UsePassive, uploadUrl, requestStream,
uploadRequest)

End If

'retry if failed

If requestStream Is Nothing Then

Base.WaitForServer(host)

AttemptFtpConnect(username, password, UsePassive, uploadUrl, requestStream,
uploadRequest)

End If

'if failed give up

If requestStream Is Nothing Then

Base.successorfail = "FAILURE"

Base.failreason = "Cannot connect to FTP server."

End If

'send file over connection

If Not requestStream Is Nothing Then

SendFile(fileName, requestStream, uploadRequest)

End If

Base.ParentForm.SetText("Upload was a " & Base.successorfail)

End Sub

Private Sub SendFile(ByRef filename As String, ByRef requestStream As
Stream, ByRef uploadRequest As FtpWebRequest)

Base.ParentForm.SetText("Uploading data. 0% done.")

Dim fileStream As FileStream = Nothing

'get stats so we can update pretty gui status

Dim f As New System.IO.FileInfo(filename)

Dim fileSize As Long = f.Length

f = Nothing

Dim lastPercent As Integer = 0

Dim totalSent As Long = 0

'read local file in chunks, copying to server

fileStream = File.Open(filename, FileMode.Open)

Dim buffer(1024) As Byte

Dim bytesRead As Integer

Try

While True

'read from file

bytesRead = fileStream.Read(buffer, 0, buffer.Length)

If bytesRead = 0 Then

Exit While

End If

'write to ftp stream

requestStream.Write(buffer, 0, bytesRead)

'log percent to gui if changing

totalSent = totalSent + bytesRead

lastPercent = System.Math.Truncate(100 * (totalSent / fileSize))

If lastPercent Mod System.Convert.ToInt16(Base.Ini.refreshgui) = 0 Then

Base.ParentForm.SetText(String.Format("Uploading data. {0:F0}% done.",
lastPercent))

End If

End While

Catch ex As Exception

Base.LogToSummary(vbCrLf & "Data upload failed before completion.")

Base.LogToDebug(String.Format("exception! message:[{0}] source:[{1}]",
ex.Message, ex.Source))

Base.successorfail = "FAILURE"

Base.failreason = "Data upload failed before completion."

End Try

requestStream.Close()

'make sure server took it, look for server to say complete

Dim uploadResponse As FtpWebResponse = Nothing

uploadResponse = uploadRequest.GetResponse()

If uploadResponse.StatusDescription.ToLower.Contains( "transfer complete") Or
uploadResponse.StatusDescription.StartsWith("226") Then

Base.LogToSummary(vbCrLf & "Data upload successful.")

Base.successorfail = "SUCCESS"

Else

Base.LogToSummary(vbCrLf & "Data upload complete, but remote server failed
to confirm reception.")

Base.successorfail = "FAILURE"

Base.failreason = "Data upload complete, but remote server failed to confirm
reception."

End If

uploadResponse.Close()

requestStream.Close()

fileStream.Close()

End Sub

End Class
Dec 14 '06 #1
1 1440
No takers? Is there a different group I should post this message to?
Dec 14 '06 #2

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

Similar topics

16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
15
by: cedgington | last post by:
I wanted to take advantage of the large set of functionality offered by the framework, so for my latest project I'm using managed C++ with .NET v2. I'm using the gcnew operator in two different...
2
by: Crimson* | last post by:
I've got a table with an entry type as "OLE Object" in Access 2003. In the form that the table is linked to I want to insert an image (BMP) for each record. However, when I attempt to do so the...
1
sammyboy78
by: sammyboy78 | last post by:
I need to create a method for sorting my CD objects by the CD Title. I have no idea where to begin. I haven't yet covered any sorting algorithms so I need to know how I can sort this thing. I'm not...
8
by: Rob | last post by:
I have a vector of a class type and when I create an object inside a function and return that and add it to the vector, it doesn't properly keep the data inside it. So I have a few questions: 1....
23
by: Maarten | last post by:
Howdy, Recently I switched from a Windows PC to Mac OS-X 10.5 (php v5.2.6) and I have a little problem with one function within my cd-management script. For extracting a bit of info from my...
2
by: whitep8 | last post by:
Hi All, Im quite new to java and im a little stuck with something so any help you can provide would be greatly appreciated. I have 2 classes, a CD class and a CDDriver class. The CD class...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.