473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File.Create - ArgumentExcepti on was unhandled - illegal characters in path

I am having problems using the file.create method within a function
that is called when looping through an array of filepaths.

If I call my function with a hardcoded file path --C:\Temp.txt the
function creates the file as expected.

When I loop through my array I get the error - "ArgumentExcept ion was
unhandled - Illegal characters in path"

The value "C:\Temp.tx t" is the first value in the array - as it works
when hard coded and not when passed from the array I presume there is
something else I am missing.

Could this be related to character encoding?

TIA

V

Aug 16 '07 #1
4 6913
"Vlad" <vl************ ***@gmail.comsc hrieb:
>I am having problems using the file.create method within a function
that is called when looping through an array of filepaths.

If I call my function with a hardcoded file path --C:\Temp.txt the
function creates the file as expected.

When I loop through my array I get the error - "ArgumentExcept ion was
unhandled - Illegal characters in path"

The value "C:\Temp.tx t" is the first value in the array - as it works
when hard coded and not when passed from the array I presume there is
something else I am missing.
I suggest to post the code calling 'File.Create' and maybe the code used to
fill the array.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 16 '07 #2
No probs - It relates to an FTP class (included below my code) - it
works when I download a single file, or if I hard code a file name
into the destination path -

Sub FTP_DownloadFol derContents(ByV al ftpFolder As String, ByVal
sDestinationPat h As String, ByVal sMask As String)
Dim sSourceFiles As String()
Dim sDestFiles As String()
Dim objFTP As New clsFTP
Dim strSite As String
Dim strSiteDir As String
Dim strUID As String, strPwd As String

strSite = My.Settings.ftp _Server
strSiteDir = My.Settings.ftp _SOURCE_Folder
strUID = My.Settings.ftp _User
strPwd = My.Settings.ftp _Password
objFTP.RemoteHo st = strSite
objFTP.RemotePa th = strSiteDir
'slashes are optional at beginning and end of RemotePath!
objFTP.RemoteUs er = strUID
objFTP.RemotePa ssword = strPwd
objFTP.RemotePo rt = 21

'Ensure FTP folder is formatted correctly
ftpFolder = FtpFolderName(f tpFolder)

'Change to the required FTP folder
objFTP.ChangeDi rectory(ftpFold er)

If objFTP.Login() = True Then
objFTP.SetBinar yMode(True)
'UPLOAD FILE
'objFTP.UploadF ile(strFullPath , False)
'GET FILE LIST
sSourceFiles = objFTP.GetFileL ist(sMask)
sDestFiles = objFTP.GetFileL ist(sMask)
objFTP.CloseCon nection()
objFTP = Nothing

'DESTINATION SETTINGS

'LOOP THROUGH FILE LIST AND DOWNLOAD EACH FILE
Dim sTempSourceFile As String = "Test_1.txt "
Dim sTempDestFile As String = "Test_1.txt "
Dim i As Long
For i = 0 To sSourceFiles.Ge tUpperBound(0)
If Len(sSourceFile s(i)) Then
FTP_DownloadFil e(sSourceFiles( i), ftpFolder,
sDestinationPat h & "\" & sSourceFiles(i) )
End If
Next i

End If
End Sub

--------------------------------- CLASS CONTAINED BELOW THIS POINT
----------------------------------
'----------------------------------------------------------------
' Class : clsFTP.vb
' Description : This class will enable a developer to
' perform FTP Processing in VB.NET.
' The class supports such features as:
' - Uploading a file.
' - Create/Remove a directory.
' - Remove a file.
' - and much much more...
' Date : 7th February 2002.
' Conversion : The code was converted from C# code.
' Note : If this code works it was converted by
' Vick S. If it doesn't it was converted
' by someone else. :-)
' Also note that the code DOES NOT
' ACCOMODATE for proxy servers. Only
' DIRECT connections to FTP Sites.
'
' Bit Shifting within VB.NET 2002 is not supported via the
' traditional bit shifting operators (i.e. << - Bitwise left
' and >- Bitwise right).
' Dividing a number by 2^16 in VB.NET 2002 is the same as bit-
' shifting right 16 positions.
' Multiplying a number by 2^16 in VB.NET 2002 is the same as
' bit-shifting left 16 positions.
'
' Check out the following MSDN Article on bitshifting in
' VB.NET 2003:
' - Visual Basic .NET 2003 Language Changes
' - By Duncan Mackenzie.
'----------------------------------------------------------------
Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Net.Sock ets

' Main FTP Class.
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

' 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 = "microsoft"
m_sRemotePath = "."
m_sRemoteUser = "anonymous"
m_sRemotePasswo rd = ""
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()
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("NL ST " & sMask)

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

'
' 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()
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
Throw New IOException("Ca n't connect to remote server")
End Try

Return s
End Function

#End Region

#Region " *** Example Code *** "
'
' Copy and paste the code below into a VB WebForm or WinForm
' application and then do the following:
'
' 1). From within the ASP.NET or WinForm app set a
' reference to the FTP.dll and BitOperators.dl l
' files.
' 2). At the top of the application code file
' (E.g WebForm1.aspx.v b or Form1.vb) type in
' Imports FTP
' 3). Compile the application and run.
' 4). Have fun.

'Protected Sub TestFTP()
' Dim ff As clsFTP

' Try
' '-------------------------------------------
' ' OPTION 1
' ' --------
' '
' ' Create an instance of the FTP Class.
' 'ff = New clsFTP()

' ' Setup the appropriate properties.
' 'ff.RemoteHost = "microsoft"
' 'ff.RemoteUser = "ftpuser"
' 'ff.RemotePassw ord = "password"
' '-------------------------------------------

' '-------------------------------------------
' ' OPTION 2
' ' --------
' ' Pass the values into the constructor
' ' instead. These can be overridden by simply
' ' setting the appropriate properties on the
' ' instance of the clsFTP Class.
' ff = New clsFTP("microso ft", _
' ".", _
' "ftpuser", _
' "password", _
' 21)

' ' Attempt to log into the FTP Server.
' If (ff.Login()) Then
' '
' ' Move the to Area1\Section1\ Subby1\ directory.
' ff.ChangeDirect ory("Area1")
' ff.ChangeDirect ory("Section1")

' 'ff.CreateDirec tory("Subby1")
' ff.ChangeDirect ory("Subby1")
' ff.SetBinaryMod e(True)

' ' Upload a file.
' 'ff.UploadFile( "d:\general\sec ureapps.pdf")

' ' Download a file.
' 'ff.DownloadFil e("secureapps.p df", "d:\general
\secureapps.pdf ")

' ' Remove a file from the FTP Site.
' If (ff.DeleteFile( "secureapps.pdf ")) Then
' Response.Write( "File has been removed from FTP
Site")
' 'MessageBox.Sho w("File has been removed from FTP
Site")
' Else
' Response.Write( "Unable to remove file from FTP
Site. Message from server: " & ff.MessageStrin g & "<br>")
' 'MessageBox.Sho w("Unable to remove file from FTP
Site")
' End If

' ' Rename a file on the FTP Site.
' 'If (ff.RenameFile( "secureapps.pdf ", "newapp.pdf "))
Then
' ' Response.Write( "File has been renamed")
' ' MessageBox.Show ("File has been renamed")
' 'End If

' 'ff.ChangeDirec tory("..")
' 'If (ff.RemoveDirec tory("Subby1")) Then
' ' Response.Write( "Directory has been removed<br>")
' ' ' MessageBox.Show ("Directory has been removed")
' 'Else
' ' Response.Write( "Unable to remove the directory.
Message from server: " & ff.MessageStrin g & "<br>")
' ' ' MessageBox.Show ("Unable to remove the
directory.")
' 'End If
' End If

' Catch ex As System.Exceptio n
' ' ASP.NET
' Response.Write( ex.Message & "<BR>")
' Response.Write( "Message from FTP Server was: " &
ff.MessageStrin g)

' ' WinForms
' 'Messagebox.Sho w(ex.Message)
' 'MessageBox.sho w("Message from FTP Server was: " &
ff.MessageStrin g)
' Finally
' '
' ' Always close down the connection to ensure that
' ' there are no "stray" Fido's Fetching data. In
' ' other words, no stray/limbo/not-in-use FTP
' ' connections.
' ff.CloseConnect ion()
' End Try
'End Sub

#End Region

End Class

Aug 17 '07 #3
Problem solved - It related to how it 'split' the directory listing
and there was a line feed in the file name
Aug 17 '07 #4
"Vlad" <vl************ ***@gmail.comsc hrieb:
Sub FTP_DownloadFol derContents(ByV al ftpFolder As String, ByVal
sDestinationPat h As String, ByVal sMask As String)
[...]
FTP_DownloadFil e(sSourceFiles( i), ftpFolder,
sDestinationPat h & "\" & sSourceFiles(i) )
Just a little note: I suggest to use 'System.IO.Path .Combine' instead of
'... & "\" & ...' to concatenate path components. Your code will fail if
'sDestinationPa th' is "C:\".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 17 '07 #5

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

Similar topics

5
1113
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up until the CDO.DropDirectory.GetMessages() method is called. At this point, the files are locked until I shut down the service. After processing and delivery, I need to be able to delete all the files in the drop directory. I can delete them via...
4
2212
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use reflection. The code I supplied is based on the SqlDataAdapter with reflection. The error occurs when trying to create the delegate that will be passed in to EventInfo.AddEventHandler. I get the following error: An unhandled exception of type...
3
26267
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
6
4468
by: Chang | last post by:
How to get SHA1 or MD5 of a big file (+5MB - 20GB) as I can't read 20GB into memory. -- Chang.
7
331
by: Bart | last post by:
When I try to upload a file from whithin a form, it works locally. But when i deploy my asp.net application, i got the error 'uri formats are not supported'. I thought it has something to do with permissions, so i looked in the target-directory from the upload, and i have these permissions : everyone-full control. What could be the problem ? Bart
6
2583
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.PathTooLongException: The path is too long
1
3165
by: Thomas | last post by:
Hi, I have written a simple web application in asp.net 1.1.4322. following is the code written in Page_Load private void Page_Load(object sender, System.EventArgs e) { string str = System.Windows.Forms.Application.ExecutablePath Response.Write(str); }
10
5931
by: Academia | last post by:
I'd like to check a string to see that it is a valid file name. Is there a Like pattern or RegEx that can do that. 1) Just the file name with maybe an extension 2)A full path An help for either of the above would be appreciated.
1
1996
by: DR | last post by:
when i reference a com object by regsvr32 it then find it in the COM tab, it works ok. but when i reference a com object by referencing the .dll file i get this error in my C# application: Error 1 The "ResolveManifestFiles" task failed unexpectedly. System.ArgumentException: Illegal characters in path. at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String str) at
0
8946
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
8774
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
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.