Я пытаюсь переместить файлы с кодом ниже с ftp://a.domain.con
на 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
Проблема в том, что в первой строке
Dim fStream As New FileStream(destinationFile, FileMode.Create)
я получаю The given path's format is not supported.
ошибка.
Исходное имя файла ftp: //a.domain.con/102425547_��������_14.2.2011_1.zip, а конечное значение - * 1014.* ftp: //b.domain.con/102425547_��������_14.2.2011_1.zip
Кстати, здесь идет StackTrace ...
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean 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)
и символы are - греческие!