0
我嘗試使用下面的代碼移動文件從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 和目標之一是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)
和 字符是希臘的!
我想知道爲什麼你決定FileStream與FTP URL(或一般的URL)工作。 – 2011-02-15 18:50:18
該代碼錯誤95%。 – SLaks 2011-02-15 18:51:01