The given path's format is not supported
I try to move files with code below from ftp://a.domain.con
to ftp://b.domain.con
Public Function TransferFile(ByVal originalFile As String, ByVal destinationFile As String, ByVal userName As String, ByVal password As String) As String
Try
Dim fStream As New FileStream(destinationFile, FileMode.Create)
Dim fileRequest As FileWebRequest = DirectCast(FtpWebRequest.Create(New Uri(originalFile)), FileWebRequest)
fileRequest.Method = WebRequestMethods.Ftp.DownloadFile
fileRequest.Credentials = New NetworkCredential(userName, password)
Dim response As WebResponse = fileRequest.GetResponse()
Dim stream As Stream = response.GetResponseStream()
Dim buffer As Byte() = New Byte(1023) {}
Dim size As Long = 0
Dim totalRead As Integer = stream.Read(buffer, 0, buffer.Length)
While totalRead > 0
size += totalRead
fStream.Write(buffer, 0, totalRead)
totalRead = stream.Read(buffer, 0, 1024)
End While
fStream.Close()
stream.Close()
Return "File transfered"
Catch ex As SecurityException
Return ex.Message
Catch ex As Exception
Return ex.Message
End Try
End Function
The problem is that on the first line
Dim fStream As New FileStream(destinationFile, FileMode.Create)
i get The given path's format is not supported.
error.
The Original filename is ftp://a.domain.con/102425547_��������_14.2.2011_1.zip and the Destination one is ftp://b.domain.con/102425547_��������_14.2.2011_1.zip
By the way here comes the StackTrace...
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, B开发者_如何学JAVAoolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
and the �������� characters are Greek ones!
You cannot use FileStream
with FTP.
Instead, you need to create two FtpWebRequest
s (one to read and one to write).
精彩评论