Использую рекурсивную процедуру для закачки на FTP каталога с данными, расположенного локально на машине:
Код | Private Sub ToFtp(ByVal CopySource3 As String, ByVal CopyDest3 As String, ByVal cred3 As ICredentials) Dim pus As String = "" For Each f As String In Directory.GetFiles(CopySource3) Try Dim wc = New WebClient() wc.Credentials = cred3 pus = IIf(Path.GetFileName(f.Substring(CopySource3.Length + 1)).StartsWith("\"), Path.GetFileName(f.Substring(CopySource3.Length + 1)), Path.GetFileName(f.Substring(CopySource3.Length))) Dim uri1 As New System.Uri(String.Format("{0}/{1}", Dest3, pus)) wc.UploadFileAsync(uri1, f) Catch ex As Exception ' End Try Next For Each d As String In Directory.GetDirectories(CopySource3) Dim newdir As String = "" Try pus = IIf(Path.GetFileName(d.Substring(CopySource3.Length + 1)).StartsWith("\"), Path.GetFileName(d.Substring(CopySource3.Length + 1)), Path.GetFileName(d.Substring(CopySource3.Length))) newdir = String.Format("{0}/{1}", Dest3, pus) Dim req = DirectCast(WebRequest.Create(newdir), FtpWebRequest) req.Credentials = cred3 req.Method = WebRequestMethods.Ftp.MakeDirectory req.GetResponse() Catch ex As Exception ' End Try
ToFtp(d, newdir, cred3) Next End Sub
|
Через некоторое время, при попытке создать очередной каталог, req.GetResponse() вываливается в исключение "Запрос был прерван: Запрос отменен.". Что это может быть? Кто-нибудь может мне что-то подсказать? |